Search by

jblond / php-cli

JBlond

php command line / cli scripting classes

Package info

github.com/JBlond/php-cli

pkg:composer/jblond/php-cli

Statistics

Installs: 11 145

Dependents: 1

Suggesters: 1

Stars: 3

Open Issues: 0

1.1.0 2026-10-14 07:41 UTC

This package is auto-updated.

Last update: 2026-10-14 07:42:37 UTC


README

composer require jblond/php-cli

php command line / cli scripting classes

Example

<?php
use jblond\cli\Cli;
use jblond\cli\CliColors;

$cli = new Cli();
$colors = new CliColors();

$string = $colors->getColoredString('This is a test','red','black');
$cli->output($string); // normal 
$cli->error($string); // error 

// This input requires Hello or world as input
$cli->input('Hello world: ',array('Hello','world'));

// This input requires only test

$cli->input('Test2: ', 'test');


// This input requires any input

$cli->input('Free input: ', '');

// Question with default N 
$answer = $cli->input('Do this? y/N', array('y','n','Y','N'), 'N');
echo $answer;

Parameter example

<?php
$cli = new Cli();
$cli->addOption('v')->addOption('output', 'file.txt')->addOption('threads', 8);
$command = 'my-program ' . $cli->buildArguments();
echo $command;
exec($command, $output, $returnCode);

Inspired by the php.net docs http://php.net/manual/en/features.commandline.io-streams.php

and a modified version of http://www.if-not-true-then-false.com/2010/php-class-for-coloring-php-command-line-cli-scripts-output-php-output-colorizing-using-bash-shell-colors/