PHPackages                             martijnvdb/php-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. martijnvdb/php-cli

ActiveLibrary[CLI &amp; Console](/categories/cli)

martijnvdb/php-cli
==================

Command line interface library for PHP

0.3.0(4y ago)216MITPHP

Since Apr 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/martijnvdb87/php-cli)[ Packagist](https://packagist.org/packages/martijnvdb/php-cli)[ Docs](https://github.com/martijnvdb87/php-cli)[ RSS](/packages/martijnvdb-php-cli/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

PHP CLI
=======

[](#php-cli)

This library helps you to create CLI applications quicky.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require martijnvdb/php-cli
```

Usage
-----

[](#usage)

Add the composer autoloader to your application and create a new instance of the CLI class. To run the application, use the `run()` method. This example will be placed in a file called `myapp` (without the `.php` extension).

```
require __DIR__ . '/vendor/autoload.php';

use Martijnvdb\PhpCli\Cli;

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

To add a default command to the application use the `add()` method. Use a callback function as the first argument. This callback will be called without giving any extra arguments. To execute the script, run `php myapp`.

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

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

The `add()` method can also be used to register a command to your application. This example will be executed by running `php myapp helloworld`.

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

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

Using the $options variable
---------------------------

[](#using-the-options-variable)

The `$options` object will contain all the command line arguments. You can retrieve the values using the `all()` and `get()` methods. The example will return the following while running `php myapp helloworld --message "Hello, World!"'`.

```
$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!";
})
```

Using the $output variable
--------------------------

[](#using-the-output-variable)

The `$output` object will help you formatting your output.

### BB Code

[](#bb-code)

This library support a custom version of BB code to help you style your output. You can mix and match any tags as long as they start with an opening and closing tag.

```
$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]');
```

##### Styling

[](#styling)

These will change the style of the text.

`[bold]`, `[b]`, `[dim]`, `[italic]`, `[i]`, `[underline]`, `[u]`, `[blink]`, `[inverse]`, `[reverse]`, `[invisible]`, `[strikethrough]`, `[s]`

##### Text colors

[](#text-colors)

These will change the color of the text.

`[black]`,`[red]`,`[green]`,`[yellow]`,`[blue]`,`[magenta]`,`[cyan]`,`[white]`

##### Background colors

[](#background-colors)

These will change the background color of the text.

`[bg:black]`, `[bg:red]`, `[bg:green]`, `[bg:yellow]`, `[bg:blue]`, `[bg:magenta]`, `[bg:cyan]`, `[bg:white]`

### $output Methods

[](#output-methods)

The `$output` object contains the following methods:

#### Basic text

[](#basic-text)

Four basis text output methods. The only difference between them is how they handle new lines.

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

#### Version

[](#version)

Output the current version of the application.

```
$output->version();
```

#### Columns

[](#columns)

Output a formatted column. The `$rows` variable is an array containing arrays in which each entry is a cell. The `$column_styles` variable allows you to style a full column in the same style. You should use the BB code without brackets for this.

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

Take a look at `examples/generate` to see some examples of how to use these methods.

Input Helper Class
------------------

[](#input-helper-class)

This library also contains a helper class which allows the application to easily get a specific input of the user.

```
$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();
```

Example of the choice input helper:

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

### Input methods

[](#input-methods)

#### Force the use to give an input

[](#force-the-use-to-give-an-input)

If the given input is empty, then a required message will show up.

```
$input->required(string $message);
```

#### Set a default

[](#set-a-default)

If the user doesn't give an input, the given default value will be returned.

```
$input->setDefault($default);
```

#### Set the invalid message

[](#set-the-invalid-message)

The message that will show up when the user enters an invalid input.

```
$input->setInvalidMessage(string $message);
```

#### Set the input styling

[](#set-the-input-styling)

The `$options` array can be filled with BB code tags without the brackets (eg. `['red', 'bold']`).

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

Progress Helper Class
---------------------

[](#progress-helper-class)

The Progress class shows a progressbar in the console. Using a float between `0` and `1` as an argument in the `set()` method, you can set the current percentage of the progressbar. The progressbar will also display how long it is running and the expected remaing time (ETA). The `start()` method will start the timer for those values. The `stop()` method will stop the timers and the progressbar.

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

### Progress Customization

[](#progress-customization)

You can customize the look of the progressbar using the `size()`, `foreground()` and `background()` methods.

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

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

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Total

4

Last Release

1801d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16452270?v=4)[martijnvdb](/maintainers/martijnvdb)[@MartijnvdB](https://github.com/MartijnvdB)

---

Top Contributors

[![martijnvdb87](https://avatars.githubusercontent.com/u/41451264?v=4)](https://github.com/martijnvdb87 "martijnvdb87 (34 commits)")

---

Tags

clilibraryphpcli

### Embed Badge

![Health badge](/badges/martijnvdb-php-cli/health.svg)

```
[![Health](https://phpackages.com/badges/martijnvdb-php-cli/health.svg)](https://phpackages.com/packages/martijnvdb-php-cli)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B11.3k](/packages/symfony-console)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M286](/packages/nunomaduro-termwind)[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[wp-cli/php-cli-tools

Console utilities for PHP

68325.0M367](/packages/wp-cli-php-cli-tools)[socialengine/sniffer-rules

A Lumen 5 and Laravel 5 SquizLabs Code Sniffer 2.0 artisan command. Detect violations of a defined coding standard. It helps your code remains clean and consistent.

1248.2k1](/packages/socialengine-sniffer-rules)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
