phico/cli

Lightweight terminal support for Phico

dev-main 2024-09-04 10:40 UTC

This package is auto-updated.

Last update: 2024-11-04 11:06:55 UTC


README

Lightweight terminal support for Phico

Installation

Using composer

composer require phico/cli

Usage

CLI provides a handful of useful methods for terminal interaction.

It is useful when creating your own commands.

Cli

Write a line to the terminal

$input = write('Hello world');
Continue on the same line
write(', this is Phico', $newline = false);
Colour support

Use error(), info(), success(), warning() to use different highlight colours.

Request user input

$input = prompt('What is your name? ');
Limit choices in response
// only one of red, blue or green is accepted
$input = prompt('What is your favourite colour? ', [
    'red',
    'blue',
    'green
]);

Write a title

$input = title('This will be underlined');

// This will be underlined
// =======================

Draw a table

$data = [
    ['Kermit', 'Green'],
    ['Fozzy Bear', 'Brown'],
    ['Miss Piggy', 'Pink'],
    ['Gonzo', 'Blue'],
];
$headings = [ 'Name', 'Colour' ];

$input = table($data, $headings);

Args

Args handles terminal inout by organising it into flags (short or long), arguments and values.

Flags

Specify single character flags with a single dash

phico -v

Multiple single flags can be set with a single dash

phico -vrt

Use has() to check if a flag is set

phico -vrt
$args->has('v'); // true
$args->has('r'); // true
$args->has('t'); // true

$args->has('a'); // false

Issues

CLI is considered feature complete, however if you discover any bugs or issues in it's behaviour or performance please create an issue, and if you are able a pull request with a fix.

Please make sure to update tests as appropriate.

For major changes, please open an issue first to discuss what you would like to change.

License

BSD-3-Clause