Cli クラス

Interact with the command line by accepting input options, parameters and output text.

beep($num = 1)

The beep method fires a system beep on the computer running the command.

静的 はい
パラメータ
パラメータ デフォルト 説明
$num 1 Number of beeps.
返り値 void
Cli::beep(25);

color($text, $foreground, $background = null)

The color method changes the color of a piece of text.

静的 はい
パラメータ
パラメータ デフォルト 説明
$text 必須 String to be colored.
$foreground 必須 Foreground color of the string.
$background null Background color of the string.
返り値 string
if (true === false)
{
	$message = Cli::color('Error: The universe is broken.', 'red');
}

else
{
	$message = Cli::color('All is well with the world.', 'green');
}

Cli::write($message);

error($text)

The error method will write a line of text to the command line as an error (similar to write but uses STDERR instead of STDOUT.

静的 はい
パラメータ
パラメータ デフォルト 説明
$text empty string Text to output to STDERR for the output.
返り値 void
Cli::error('Failure: You hit the wrong key with your chubby hands, try using a stick to poke the keyboard.');

prompt($question = null, $options = array())

The read method prompts the user for input.

静的 はい
パラメータ
パラメータ デフォルト 説明
$question null Ask the user a question and wait for input.
$options array() An array of options for the user to select from.
返り値 string
// Waits for any key press
Cli::prompt();

// Takes any input
$color = Cli::prompt('What is your favorite color?');

// Takes any input, but offers default
$color = Cli::prompt('What is your favorite color?', 'white');

// Will only accept the options in the array
$ready = Cli::prompt('Are you ready?', array('y','n'));

option($name, null)

The option accepts an option from the initial command.

静的 はい
パラメータ
パラメータ デフォルト 説明
$name Required Name of the option.
$default null A default value in case the option is not provided.
返り値 string
$ php index.php user -v --v -name=John --name=John

wait($seconds = 0, $countdown = false)

The wait method will make the cli output wait for a given number of seconds and optionally show a countdown.

静的 はい
パラメータ
パラメータ デフォルト 説明
$seconds 0 Number of seconds to wait.
$countdown false Show the countdown in the output.
返り値 void
Cli::write('Loading...');
Cli::wait(5, true);

write($text = '', $foreground = null, $background = null)

The write method will write a line of text to the command line.

静的 はい
パラメータ
パラメータ デフォルト 説明
$text empty string Text to output to the command line.
$foreground null Foreground color of the string.
$background null Background color of the string.
返り値 void
Cli::write('Hello World!');