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

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

vtardia/cli-parser
==================

A command line parser utility for PHP scripts.

1.0.0(11y ago)03442MITPHPPHP &gt;=5.3

Since Mar 26Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (2)

CLIParser
=========

[](#cliparser)

CLIParser is a PHP utility that parses the command line of a PHP script detecting short and long options, switches and arguments.

The output is similar to Linux's `getopt_long()` native function in both behavior and configuration, both long and short options can be validated, for example:

```
$shortOptions = 'vho:a';

$longOptions = array(
    array('id', TRUE),
    array('name', TRUE),
    array('verbose', FALSE, 'v'),
    array('output', TRUE, 'o'),
);
```

The above code defines

- the long option `--verbose` with short equivalent `-v` and no required parameter
- the long option `--output`, with short equivalent `-o` and a required parameter
- the long options `--id` and `--name` with required parameters and no short equivalent
- the short options `-h` and `-a` with no long equivalent and no required parameter

With CLIParser you can build scripts like:

```
$ myscript -abc -v -o somefile.log --name=SomeName --other-option OtherValue Argument1 Argument2...ArgumentN
```

In addition, you can parse the arguments starting from an arbitrary position, so you can have:

```
$ myscript SomeCommand [OPTIONS] Argument1...ArgumentN
```

Usage
-----

[](#usage)

```
// require CLIParser.php library file or use an autoloader (eg. Composer)

use CLIParser\CliParser;

// Define some options
$shortOptions = 'vo:';
$longOptions = array(
    array('verbose', false, 'v'),
    array('output', true, 'o'),
);

// Create a parser...
$cli = new CLIParser($shortOptions, $longOptions);

// ... and use it!

// Executable name or path
$program = $cli->program();

// Array of valid options with values
$options = $cli->options();

// Array of arguments
$arguments = $cli->arguments();
```

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

[](#installation)

```
$ composer require vtardia/cli-parser
```

Requirements
------------

[](#requirements)

PHP 5.3 or better, PHPUnit in order to run tests.

Contributing
------------

[](#contributing)

See CONTRIBUTING file.

Running the Tests
-----------------

[](#running-the-tests)

```
$ composer test
```

Credits
-------

[](#credits)

CLI Parser uses some code written by [Patrick Fisher](https://github.com/pwfisher/CommandLine.php).

Contributor Code of Conduct
---------------------------

[](#contributor-code-of-conduct)

Please note that this project is released with a [Contributor Code of Conduct](http://contributor-covenant.org/). By participating in this project you agree to abide by its terms. See CODE\_OF\_CONDUCT file.

License
-------

[](#license)

CLIParser is released under the MIT License. See the bundled LICENSE file for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

4071d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/539034?v=4)[Vito Tardia](/maintainers/vtardia)[@vtardia](https://github.com/vtardia)

---

Top Contributors

[![vtardia](https://avatars.githubusercontent.com/u/539034?v=4)](https://github.com/vtardia "vtardia (2 commits)")

---

Tags

cliconsoleshellcommands

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

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

An interactive shell for modern PHP.

9.8k545.6M719](/packages/psy-psysh)[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)[kevinlebrun/colors.php

Colors for PHP CLI scripts

3426.7M45](/packages/kevinlebrun-colorsphp)[wp-cli/php-cli-tools

Console utilities for PHP

68325.0M367](/packages/wp-cli-php-cli-tools)

PHPackages © 2026

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