PHP code example of shso / cli

1. Go to this page and download the library: Download shso/cli library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shso / cli example snippets




cli\argc(); // returns 3

cli\arg(); // returns ['script.php', 'ARG1', 'ARG2', 'ARG3']
cli\arg(2); // returns 'ARG2'
cli\arg(4, 'foo'); // returns 'foo'

cli\opt(); // returns ['f' => true, 'action' => 'ACTION']
cli\opt('f'); // returns true
cli\opt('action'); // returns 'ACTION'
cli\opt('q'); // returns null
cli\opt('foo', 'bar'); // returns 'bar'

cli\usage([
    'args' => [ 'REQUIRED_ARG', '[OPTIONAL_ARG]' ],
]);

cli\usage([
    'opts' => [
        '-f' => null, // optional, without arg, short
        '*c' => null, // g, long
        '*config' => 'CONFIG', // 

cli\usage([
    'args' => [ 'CONFUSING_ARG' ],
    'opts' => [
        '-f' => null,
    ],
    'desc' => [
        'CONFUSING_ARG' => 'Some descriptions that make the arg not confusing!',
        '-f' => 'Describe -f option can force the operation or whatever.',
    ],
]);
sh
$ curl -fL -O https://github.com/ShahinSorkh/php-cli/raw/master/src/cli.php
# Or using wget
$ wget https://github.com/ShahinSorkh/php-cli/raw/master/src/cli.php
sh
$ php script.php -f --action ACTION -- ARG1 ARG2 ARG3
sh
$ php script.php --opt --opt-with-arg OPT_ARG -- ARG [OPTIONAL_ARG]
sh
$ php script.php ARG1 --opt1 ARG2 --opt2 OPT2_ARG ARG3 ARG4
sh
$ php script.php --op1 ARG1
sh
$ php script.php --op1 -- ARG1
sh
$ php script.php - < somefile.txt
$ cat somefile.txt | php script.php -
sh
$ php script.php -f --file SOME_FILE
$ php customzipcompress.php --rm --compression best -f FILE1,FILE2 -d DIR1
sh
$ php script.php -t -g OPT_ARG -- ARG1