PHP code example of hasan-22 / php-command

1. Go to this page and download the library: Download hasan-22/php-command 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/ */

    

hasan-22 / php-command example snippets


composer 

use App\Console;

Console::command('command_name',function (){
    
})->purpose('Command description');

// purpose method is optional

// Run it like this
// php [scriptName.php] [command_name] [args]

Console::command('get_username',function (){
    $input = Console::input('Enter your name: ');
    echo $input;
})->purpose('This command gets the username');

// Run:
// php script.php get_username

Console::command('get_password',function (){
    $input = Console::secretInput('Enter your password:');
    echo $input;
});

// Run:
// php script.php get_password

Console::command('get_password',function (){
    $input = Console::option('--pass');
    echo $input;
});
// Run:
// php script.php get_password --pass 123456

// Output: 123456

##################### OR ########################
Console::command('get_password',function (){
    $input = Console::option('pass');
    echo $input;
});
// Run:
// php script.php get_password pass 123456

// Output: 123456

##################### OR ########################
Console::command('get_password',function (){
    $input = Console::option('pass');
    echo $input;
});
// Run:
// php script.php get_password pass=123456

// Output: 123456



Console::command('get_password',function (){
    $input = Console::option('--pass');
    echo Console::success($input);
    echo Console::error($input);
    echo Console::warning($input);
    echo Console::info($input);
    echo Console::none($input);
});

// script.php help
// or
//script.php --help
// or
//script.php -h
// or
//script.php h