PHP code example of martijnvdb / php-cli

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

    

martijnvdb / php-cli example snippets


composer 



use Martijnvdb\PhpCli\Cli;

$cli = (new Cli('First CLI App', '0.1.0'))->run();

$cli = new Cli('First CLI App', '0.1.0');

$cli->add(function ($input, $output) {
        // ...
})
->run();

$cli = new Cli('First CLI App', '0.1.0');

$cli->add('helloworld', function ($input, $output) {
        // ...
})
->run();

$cli->add('helloworld', function ($options, $output) {
    // This will return all options
    $options = $options->all();
    
    // This will return the value of the '--message' option
    $message = $options->get('--message'); 
    
    // Will return the value of the '--message' or '-m' option
    $message = $options->get('--message', '-m');
 
    // $options = ["--message" => "Hello, World!"];
    // $message = "Hello, World!";
})

$output->line('[bold]Bold Text[/bold]');
$output->line('[red]Red Text[/red]');
$output->line('[bg:green]Green Background[/bg:green]');
$output->line('[bg:white][magenta][italic]Italic magenta text on a white background[/italic][/magenta][/bg:white]');

$output->echo(string $value = '');
$output->line(string $value = '');
$output->lines(array $lines = []);
$output->paragraph(string $value = '');

$output->version();

$output->columns(string $label, array $rows = [], array $column_styles = []);

$input = Input::text(string $label)->get();
$input = Input::number(string $label)->get();
$input = Input::url(string $label)->get();
$input = Input::email(string $label)->get();
$input = Input::choice(string $label, array $options)->get();

$input = Input::choice('[yellow]Select an option[/yellow] [green](1/2/3)[/green]:', [
        '1' => 'Option 1',
        '2' => 'Option 2',
        '3' => 'Option 3'
    ])
    ->

$input->

$input->setDefault($default);

$input->setInvalidMessage(string $message);

$input->inputStyling($options = []);

$progress = Progress::new();
$progress->start();
$progress->set(0.25);
$progress->set(0.5);
$progress->set(0.75);
$progress->set(1);
$progress->stop();

// Default size
$progress->size(30);

// Default templates
$progress->foreground('[bg:white][invisible]|[/invisible][/bg:white]');
$progress->background('[bg:240][invisible].[/invisible][/bg:240]');