PHPackages                             rayanlevert/command-line-interface - 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. rayanlevert/command-line-interface

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

rayanlevert/command-line-interface
==================================

Dependency-free command line interface (CLI) handling arguments and easily personalizing output in the PHP userland

v3.0.5(5mo ago)1131BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Oct 14Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/rayanlevert/command-line-interface)[ Packagist](https://packagist.org/packages/rayanlevert/command-line-interface)[ RSS](/packages/rayanlevert-command-line-interface/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (30)Used By (0)

Dependency-free command line interface (CLI) handling arguments and easily personalizing output in the PHP userland
-------------------------------------------------------------------------------------------------------------------

[](#dependency-free-command-line-interface-cli-handling-arguments-and-easily-personalizing-output-in-the-php-userland)

[![Packagist Version](https://camo.githubusercontent.com/76e919799fe2fd13a8596640a518278d0616b92f6f34983b871add9615ef8e30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726179616e6c65766572742f636f6d6d616e642d6c696e652d696e74657266616365)](https://packagist.org/packages/rayanlevert/command-line-interface)[![PHP from Packagist](https://camo.githubusercontent.com/c534e85215b2b1f0349786c96d2f002c69e5a614641edce2413b9909b19ca0f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726179616e6c65766572742f636f6d6d616e642d6c696e652d696e74657266616365)](https://packagist.org/packages/rayanlevert/command-line-interface)[![codecov](https://camo.githubusercontent.com/501b1282e19db8adf96901f4d0b3276abbeb452f6812bfc83c20f00b19579cb8/68747470733a2f2f636f6465636f762e696f2f67682f726179616e6c65766572742f636f6d6d616e642d6c696e652d696e746572666163652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/rayanlevert/command-line-interface)

> Version &gt;= **3.0** supports only **php8.4** with all brand new features, for &gt;= **php8.1**, version **2.0** is still supported.

### **RayanLevert\\Cli\\Arguments\\Argument** defines what is an Argument

[](#rayanlevertcliargumentsargument-defines-what-is-an-argument)

An argument has a name and different options and can only be of type `integer`, `double` ou `string` (if the option `noValue` is used, it will be `bool`)

```
new \RayanLevert\Cli\Arguments\Argument(string $name, array $options = [])
```

```
- description (string) Description of the argument
- defaultValue (float|int|string) Default value if the argument is not handled
- required (bool) If the argument must be present and parsed
- castTo (string) PHP type - If the argument has a type other than string, its value will be casted
- noValue (bool) If a prefixed argument doesn't need a value -> boolean cast
- prefix (string) Short prefix (-u)
- longPrefix (string) Long prefix (--user)

```

A `RayanLevert\Cli\Arguments\Exception` can be thrown if options are not compliant (see `__construct()`)

### **RayanLevert\\Cli\\Arguments** is a collection of Argument capable of parsing values from `argv` (array of strings)

[](#rayanlevertcliarguments-is-a-collection-of-argument-capable-of-parsing-values-from-argv-array-of-strings)

```
new \RayanLevert\Cli\Arguments(\RayanLevert\Cli\Arguments\Argument ...$oArguments)
```

> Required arguments must be declared first, before not required ones

#### Recovery of parsed values is done via the method `parse(string ...$arguments): void`

[](#recovery-of-parsed-values-is-done-via-the-method-parsestring-arguments-void)

> To parse arguments from the actual CLI, use `parse(...$argv)` (with declaring `global $argv;` if you are not in the global scope)

Associates each parsed value to its Argument in the collection

The parsed value of an argument is recoverable by `::get(string $argumentName)`

By default, `NULL` is returned; `integer`, `float` or `string` can be returned if the argument has been parsed and option `castTo` has been set

- If castTo is `integer` or `float`, the value must be a numeric string (asserts with `is_numeric()`)
- Si castTo is `string` (by default), the value will be the one parsed

### Implementation

[](#implementation)

```
$oArguments = new Arguments(new Argument('arg1'));
$oArguments->get('arg1') // NULL

$oArguments = new Arguments(new Argument('arg1', ['defaultValue' => 'test']));
$oArguments->get('arg1') // test

$oArguments = new Arguments(new Argument('arg1', ['castTo' => 'float', 'defaultValue' => 14.3]));
$oArguments->get('arg1') // 14.3

$oArguments = new Arguments(new Argument('arg1', ['required' => true]));
$oArguments->parse(); // ParseException arg1 is required
$oArguments->parse('test'); // OK $oArguments->get('arg1') = test

// Parsing optional arguments
$oArguments = new Arguments(new Argument('arg1'), new Argument('arg2'));
$oArguments->parse('test1'); // $oArguments->get('arg1') = test1, $oArguments->get('arg1') = NULL
$oArguments->parse('test1', 'test2'); // $oArguments->get('arg1') = test1, $oArguments->get('arg1') = test2

// Parsing prefixed arguments
$oArguments = new Arguments(new Argument('arg1', ['prefix' => 'a', 'longPrefix' => 'arg']));
$oArguments->parse('-a=testValue'); // $oArguments->get('arg1') = testValue
$oArguments->parse('-a="test Value"'); // $oArguments->get('arg1') = test Value
$oArguments->parse('--arg=testValue'); // $oArguments->get('arg1') = testValue
$oArguments->parse('--arg="test Value"'); // $oArguments->get('arg1') = test Value
```

### Multiple methods are available

[](#multiple-methods-are-available)

- Adds an argument - `set(Argument $oArgument): void`
- Removes one - `remove(string $argumentName): void`
- Returns the number of arguments `count(): int`
- Prints a clean display about the informations of arguments `printArguments(): void````
      Required arguments:
        arg1 (type: string)
        arg2 (type: integer)

      Optional arguments:
        arg3 --arg3=arg3 (type: integer)
        arg4 -arg4

    ```

Personalizes the command line interface by changing the color and formatting displayed text
-------------------------------------------------------------------------------------------

[](#personalizes-the-command-line-interface-by-changing-the-color-and-formatting-displayed-text)

### **RayanLevert\\Cli\\Style** is a class that only has static methods

[](#rayanlevertclistyle-is-a-class-that-only-has-static-methods)

3 enumerations are available to stylize the output:

- `RayanLevert\Cli\Style\Background`: Background colors
- `RayanLevert\Cli\Style\Foreground`: Text colors
- `RayanLevert\Cli\Style\Attributes`: Text attributes

2 main methods are used to display formatted text

```
/**
 * Prints a string of a background color, text color and/or an attribute
*/
public static function inline(string $string, Background $bg = null, Foreground $fg = null, Attribute $at = null): void;

/**
 * Prints a string and breaks a line of a background color, text color and/or an attribute
*/
public static function outline(string $string, Background $bg = null, Foreground $fg = null, Attribute $at = null): void;
```

And one to return the formatted string instead of printing it

```
public static function stylize(string $string, Background $bg = null, Foreground $fg = null, Attribute $at = null): string;
```

Other useful methods are available:

```
/**
 * Prints a formatted string thanks to its tags of ANSI codes (Foreground, Background and Attribute)
 *
 * Useful is you want to use multiple styles in one single method call
 *
 * Tags to use are in the three enumerations thanks to the 'tryFromTag' method
*/
public static function tag(string $tag): void

====================================
｡◕‿◕｡ This is a title ｡◕‿◕｡
====================================
public static function title(string $title): void;

--- Flanked message ---\n
public static function flank(string $message, string $char = '-', int $length = 3): void;

  (◍•﹏•) Warning message\n
public static function warning(string $message): void; // colored text in yellow

  (◍•﹏•) Error message\n
public static function error(string $message): void; // colored text in red

public static function red(string $message): void; // displays a red colored text and breaks a line
public static function green(string $message): void; // displays a green colored text and breaks a line
public static function yellow(string $message): void; // displays a yellow colored text and breaks a line

// Displays according to a boolean status, a red or green text colored message and breaks a line
public static function outlineWithBool(bool $status, string $ifTrue, string $ifFalse, string $toPrecede = ''): void;

// Prints the details of an exception in red + its trace in white
public static function exception(\Exception $e, bool $withoutTrace = false): void;
```

### **RayanLevert\\Cli\\ProgressBar displays progression output through a progress bar**

[](#rayanlevertcliprogressbar-displays-progression-output-through-a-progress-bar)

```
/**
 * @param int $max Maximum value of iterations
 * @param int $numberOfSymbols Number of symbols added after each iteration
*/
$oProgressBar = new ProgressBar(int $max, int $numberOfSymbols = 50);

/**
 * @param string $title Title to add above the progress bar
 * @param Style\Foreground $fg Text color
*/
$oProgressBar->setTitle(string $title = '', Style\Foreground $fg = Style\Foreground::BLUE);

/**
 * Starts the progress bar (or restarts it, if not breaks two lines)
*/
$oProgressBar->start();

/**
 * Advances the progress bar of `$toAdvance` iterations updating the progression
*/
$oProgressBar->advance(int $toAdvance = 1);

// Finishes the progress bar (advances to the max value)
$oProgressBar->finish();
```

### Simple implementation

[](#simple-implementation)

```
// 10 is the max value -> a new symbol every new iteration
$oProgressBar = new ProgressBar(10);
$oProgressBar->start('My progress bar');

// Advances to 1 each iteration
foreach (range(1, 10) as $range) {
    $oProgressBar->advance();
}

  My progress bar
  1 / 10 [#         ]
  2 / 10 [##        ]
  ...
  10 / 10 [##########]
```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance73

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% 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 ~44 days

Total

27

Last Release

150d ago

Major Versions

v1.3.0 → v2.0.02023-12-05

v2.3.0 → v3.0.02025-01-01

v2.3.1 → v3.0.22025-06-06

v2.3.2 → v3.0.32025-06-06

v2.3.3 → v3.0.42025-07-01

PHP version history (3 changes)v1.0.0PHP ^8.1

v1.2.2PHP &gt;=8.1

v3.0.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/7253402d616a4792e6733113363a7f6918d318fb2b68fce60e5eb6d715319d69?d=identicon)[rayanlevert](/maintainers/rayanlevert)

---

Top Contributors

[![rayanlevert](https://avatars.githubusercontent.com/u/78140431?v=4)](https://github.com/rayanlevert "rayanlevert (71 commits)")[![rlevert-dis](https://avatars.githubusercontent.com/u/83226311?v=4)](https://github.com/rlevert-dis "rlevert-dis (31 commits)")

---

Tags

clicolorcommand-line-interfacedependency-freephpstyle

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rayanlevert-command-line-interface/health.svg)

```
[![Health](https://phpackages.com/badges/rayanlevert-command-line-interface/health.svg)](https://phpackages.com/packages/rayanlevert-command-line-interface)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.1k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)[codedungeon/php-cli-colors

Liven up you PHP Console Apps with standard colors

10210.1M26](/packages/codedungeon-php-cli-colors)

PHPackages © 2026

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