PHPackages                             nerou/cli-parser - 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. nerou/cli-parser

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

nerou/cli-parser
================

Parser for CLI arguments

v0.2.1(5mo ago)03.0k↑22.9%1MITPHPPHP &gt;=8.0CI passing

Since Dec 18Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/nerou42/CLIParser)[ Packagist](https://packagist.org/packages/nerou/cli-parser)[ RSS](/packages/nerou-cli-parser/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

CLI Parser
==========

[](#cli-parser)

[![License](https://camo.githubusercontent.com/90360977a387fa6c1d24d94c6debbfd82f9d12d7b868cab762ded247ad65659d/68747470733a2f2f706f7365722e707567782e6f72672f6e65726f752f636c692d7061727365722f6c6963656e7365)](https://packagist.org/packages/nerou/cli-parser)[![PHP Version Require](https://camo.githubusercontent.com/13b2186d8c4cd91a714d3d47a88ecb35b1f72d6a5f441d1548ca3ae5ad3bb409/68747470733a2f2f706f7365722e707567782e6f72672f6e65726f752f636c692d7061727365722f726571756972652f706870)](https://packagist.org/packages/nerou/cli-parser)[![Version](https://camo.githubusercontent.com/bfb2006f6e15d73b0b3cad3803f3fc1b116d9480473e4428a4141d3464cdb06c/68747470733a2f2f706f7365722e707567782e6f72672f6e65726f752f636c692d7061727365722f76657273696f6e)](https://packagist.org/packages/nerou/cli-parser)[![Psalm Type Coverage](https://camo.githubusercontent.com/3f2137387d054f93a06c7dcd45a37fbe3052dd7649a622712468b2e932916c95/68747470733a2f2f73686570686572642e6465762f6769746875622f6e65726f7534322f434c495061727365722f636f7665726167652e737667)](https://packagist.org/packages/nerou/cli-parser)

This project is build around a slightly modified version of [this fairly old comment on php.net](https://www.php.net/manual/en/features.commandline.php#83843).

This is for you, if...
----------------------

[](#this-is-for-you-if)

...you are creating CLI applications with PHP, that take some command line arguments, options, commands and/or flags.

Install
-------

[](#install)

Note: This library requires PHP 8.0+!

Use composer to install this library:

`composer require nerou/cli-parser`

There are no dependencies.

Usage
-----

[](#usage)

### Wording

[](#wording)

**Command** is just some value, e.g. `myscript.php hello`

**Option** starts with `--` and can have a value, e.g. `myscript.php --foo` or `myscript.php --foo=bar` or `myscript.php --foo bar`

**Flag** starts with `-` and is a short form of an option, e.g. `myscript.php -f` or `myscript.php -f bar`

**Argument** is everything following a standalone `--`

### Examples

[](#examples)

Minimal example with options `--foo` and `--bar` as well as the flag `-f` which is a short form of `--foo`:

```
if(PHP_SAPI !== 'cli' || !isset($_SERVER['argv'])){
  exit(1);          // exit if not run via CLI
}

$cliArgs = new CLIParser($_SERVER['argv'], '[--foo] [--bar]');
$cliArgs->setAllowedOptions(['foo', 'bar']);    // list of supported options
$cliArgs->setAllowedFlags(['f' => 'foo']);      // maps flags to options
$cliArgs->setStrictMode(true);                  // parse() will return `false` if there are options/flags that are not allowed
if(!$cliArgs->parse()){
  $cliArgs->printUsage();     // show them how to use this script
  exit(1);
}
```

Use value validation (see [PHP filters](https://www.php.net/manual/en/filter.filters.php)):

```
$cliArgs->setAllowedOptions([
    'foo' => [
        'filter' => FILTER_VALIDATE_FLOAT,
        'flags' => FILTER_FLAG_ALLOW_THOUSAND,
        'options' => [
            'min_range' => 0,
            'default' => 42                   // default value which will also be added to usage documentation
        ],
        'value_label' => 'my-val',            // for usage documentation
        'description' => 'pass some float'    // for usage documentation
    ],
    'bar' => []     // defaults to `['filter' => FILTER_DEFAULT]`
]);
```

Limitations and concerns
------------------------

[](#limitations-and-concerns)

- using a single option multiple times is not supported, e.g. `phpcpd src --exclude src/foo --exclude src/bar`

License
-------

[](#license)

This library is licensed under the MIT License. Please see [LICENSE](LICENSE) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance79

Regular maintenance activity

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

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 ~153 days

Recently: every ~172 days

Total

6

Last Release

159d ago

PHP version history (2 changes)0.1PHP &gt;=8.0 &lt;8.4

0.1.1PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![cracksalad](https://avatars.githubusercontent.com/u/28577589?v=4)](https://github.com/cracksalad "cracksalad (21 commits)")

---

Tags

cli-parserphp

###  Code Quality

Static AnalysisRector

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/nerou-cli-parser/health.svg)

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

###  Alternatives

[illuminate/console

The Illuminate Console package.

13046.0M6.5k](/packages/illuminate-console)[styleci/cli

The CLI tool for StyleCI

71470.5k9](/packages/styleci-cli)[winbox/args

Windows command-line formatter

20720.9k21](/packages/winbox-args)[tomatophp/filament-artisan

Simple but yet powerful library for running some artisan commands for FilamentPHP

3275.4k1](/packages/tomatophp-filament-artisan)[thettler/laravel-console-toolkit

This Package provides some usefully console features like the attribute syntax for arguments and options, validation, auto ask and casting.

324.1k](/packages/thettler-laravel-console-toolkit)

PHPackages © 2026

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