Commandline tools

1.0.1 2017-09-04 05:35 UTC

This package is auto-updated.

Last update: 2022-10-22 22:47:30 UTC


Commandii is a tool library for the commandline which can:

  • Show and colorize messages in ANSI colors
  • Process commandline arguments and parameters

Known issues

At the moment there are no known issues. If you find one, please let me know through https://bitbucket.org/jfabot/commandii/issues/new



To use the commandline component in your code you need to include `use Commandii\CommandLine' To retrieve the used commandline commands and arguments:

$commandLine = new \Commandii\CommandLine;

This will return an array with all of the values, example: application command --argument1=value --argument2 Will return:

[0] => command
[argument1] => value
[argument2] => 1

If there is no value for the argument it will automatically be filled with a 1.


If you want to colorize the progress of a process, you can include use Commandii\StatusMessages The StatusMessages component exists of the following functions:

dot($type, $character, $verboseMessage)

Show a progress-dot, default ., or the given alternative with $character.

$statusMessages = new StatusMessages;
$statusMessages->dot(StatusMessages::TYPE_NOTICE, 'n', 'This is a notice');


Shows a SUCCESS message in green. By default there is no spacer in front.

$statusMessages = new StatusMessages;


Shows a WARNING message in orange. By default there is no spacer in front.

$statusMessages = new StatusMessages;


Shows a ERROR message in red. By default there is no spacer in front.

$statusMessages = new StatusMessages;


Shows a SKIPPED message in cyan. By default there is no spacer in front.

$statusMessages = new StatusMessages;


Shows a given message in orange.

$statusMessages = new StatusMessages;
$statusMessages->warningText('This is the message');


Shows a given message in red.

$statusMessages = new StatusMessages;
$statusMessages->errorText('This is the message');

infoText($message, $type)

Shows a given message in the given type. If no type was given the text is in white.

$statusMessages = new StatusMessages;
$statusMessages->infoText('This is the message', StatusMessages::TYPE_INFO);

message($message, $linefeed, $verboseOnly)

The message function is used to show a message and has 2 extra arguments to control the behaviour. If linefeed is true, at the end of the message a end-of-line character is added. The second argument verboseOnly checks if the code is running in verbose mode. If so, the message will be shown, otherwise it will be discarded.

You can use this function to show a message like: Starting process

To do this

$statusMessages = new StatusMessages;
$statusMessages->message('Starting process', false, false);

This is handy when you need to show a progressbar after the text. You can use this in combination with the dot function to give feedback to the user in a compact or verbose format.


$statusMessages = new StatusMessages;

question($question, $timeout = 5)

Shows a question that can be answered with y or n. The timeout is in seconds.

$statusMessages = new StatusMessages;
$statusMessages->question('This is the question', 3);


Enables the use of ANSI colors

$statusMessages = new StatusMessages;


Disables the use of ANSI colors

$statusMessages = new StatusMessages;


You can set a variable to be watched. The value of the variable triggers if the component is using verbose or not.


Clear the verbose variable

Logcompatible output

If you need to strip the output from the color tags you can use the function AnsiColors::colorize($text, $linebreak, $flatten) By setting flatten to true, the color tags are stripped and a flat output will be returned.