Giter Site home page Giter Site logo

php-cli's Introduction

php-cli

Php cli application skeleton

Requirements

  1. PHP 7.x
  2. libssh2 library

About

This cli php script help you do some operations. It contains some base classes like ssh client or preconfigured comfortable (for me) echo class.

Using

If you need do some operations just create some user function in Cli class. For example if you want make operations in destination server, you may create one function like this:

    /**
     * Check ssh client
     */
    private function checkSshCommand(string $server)
    {
        $this->echo->msg("Try connect to server $server");

        $ssh = new Ssh_clien($server);
        $this->echo->msg(

            $ssh->exec([
                "su admin\r",
                "cd /home/admin/web",
                "dir",
                "pwd",
                "exit"
            ])
        );

        $this->echo->msg('Finish');
    }
This simple function checkSsh do:
  1. connect to destination server as root;
  2. login as admin user;
  3. change directory to /home/admin/web
  4. show current derictory;
  5. logout from admin user to root

Create functions

  1. For creating some special function you need create some method named like yourMegaMethodCommand with Command word in the end of name.
  2. If you want send parameters to your method just set var with type and default parameter (if need) like this.
private function checkSshCommand(string $server) 
{
    //... METHOD BODY
}
  1. Dont forget add some description for your method.
/**
* Your functions very clear description
*/
private function checkSshCommand(string $server) 
{
    //... METHOD BODY
}

Run commands

For running command in cli.php you can view functions help like this:

$ ./cli.php

Hello! This is cli php script for do some operations
USAGE: $cli.php command [--param1] [--param2] [param2Value]
Please use follow commands:
checkSsh:
   check ssh client
   --server (string)
test:
   Testing current utility
   --name (string)
   --is_required (bool)
   --number (int)
   --price (float) <4.18>
   --color (string) <RED>
test2:
   Test 2 some comment
   multiple
   lines
   --name <Ralf>
help:
   current help message
man:
   Show only one command description
   --cmd

or just run method

$ ./cli.php checkSsh --server servername.com

Try connect to server servername.com
domain1.com  docs.domain1.com  ds.domain1.com  m.domain1.com  domain2.com
/home/admin/web

Finish

php-cli's People

Contributors

marks12 avatar

Stargazers

Oleg Chulkov avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.