PHP code example of shaggy8871 / console

1. Go to this page and download the library: Download shaggy8871/console 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/ */

    

shaggy8871 / console example snippets



sole = new Console\Runner();

// Add one or more commands here
$console->registerAll([
    'app:command' => [
        'class' => 'Commands\CustomCommand',
        'description' => 'Add your custom command description'
    ]
]);

// Start your engines...
try {
    $console->run();
} catch(Console\Exception\CommandNotFoundException $e) {
    echo $e->getMessage() . "\n--------\n\n" . $console->getHelp();
    die();
}




namespace Commands;

use Console\CommandInterface;
use Console\Args;

class CustomCommand implements CommandInterface
{

    public function execute(Args $args)
    {

        // Convert short-form to long-form arguments
        $args->setAliases([
            'l' => 'longform'
        ]);

        // Write custom code
        // ... Do something with $args->longform or $args->getAll()

    }

}



use Console\Decorate;

echo Decorate::color('Hello, world!', 'red bold bg_white');




use Console\Decorate;

echo Decorate::color('Hello, world!', [
    Decorate::vgaBackground(9), 
    Decorate::vgaColor(52)
]);




use Console\StdOut;

StdOut::write([
    ["Hello, world!\n", 'red'],
    ["This is a second line, but in green\n", 'green']
]);



use Console\StdOut;

StdOut::disableAnsi();
StdOut::write([
    ["Hello, world!\n", 'red'],
    ["This is a second line, but in green\n", 'green']
]);