PHPackages                             deweller/cliopts - 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. deweller/cliopts

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

deweller/cliopts
================

A no-nonsense command-line options parser and help generator for PHP CLI apps.

1.0.2(13y ago)1518.3k1MITPHPPHP &gt;=5.3.0

Since Dec 1Pushed 13y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

php-cliopts [![Build Status](https://camo.githubusercontent.com/6050bd75aeabe81df25d7b5db7f617ed93cca8bb5b95745000892434fcbc988e/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f646577656c6c65722f7068702d636c696f7074732e706e67)](https://travis-ci.org/deweller/php-cliopts) [![project status](https://camo.githubusercontent.com/1329e384e679ced430c2c3c3ac28621acfe969bc2317c7fb38207535e634b43d/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f646577656c6c65722f7068702d636c696f7074732e706e67)](https://camo.githubusercontent.com/1329e384e679ced430c2c3c3ac28621acfe969bc2317c7fb38207535e634b43d/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f646577656c6c65722f7068702d636c696f7074732e706e67)
=====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-cliopts--)

A no-nonsense command-line options parser and help generator for PHP CLI apps.

Features
--------

[](#features)

- Simple one-line usage with a human readable configuration format
- Parses $argv data into an associative array similar to getopt()
- Adds error validation for missing or malformed arguments or options
- Nicely formatted help generation
- Supports options (e.g. -i 100) and named arguments (./script.php /tmp/myfile.txt)

Usage
-----

[](#usage)

### Code

[](#code)

In its simplest form, the parser can be used with one line of php code:

```
// specify the spec as human readable text
$values = CLIOpts\CLIOpts::run("
{self}
-i, --id  specify an id (required)
-o, --out  output filename
-v be verbose
-h, --help show this help
");

// show the values
echo "The values you supplied are:\n";
print_r((array)$values);
```

### CLI Input

[](#cli-input)

The interpretation of flags are somewhat flexible. The following lines are all handled in the same way by cliopts:

1. `./script.php -v -i 101 -o /tmp/myfile.txt /tmp/infile.txt`
2. `./script.php -vi 101 -o /tmp/myfile.txt /tmp/infile.txt`
3. `./script.php -v --id 101 -o /tmp/myfile.txt /tmp/infile.txt`
4. `./script.php -v --id="101" -o /tmp/myfile.txt /tmp/infile.txt`

All of the above will show this output:

```
The values you supplied are:
Array
(
    [in_filename] => /tmp/infile.txt
    [id] => 101
    [out] => /tmp/myfile.txt
    [v] =>
)

```

The Human Readable Text Specification
-------------------------------------

[](#the-human-readable-text-specification)

Let's look at the specification in the following bit of code:

```
$values = CLIOpts\CLIOpts::run("
  Usage: process_files.php [options]  []
  -i, --id  specify an id (required)
  -v be verbose
")
```

### The Usage Line

[](#the-usage-line)

The spec begins with a usage line. This line is optional. But if it is provided, here is a breakdown of how the usage line is interpreted:

```
Usage: process_files.php [options]  []
|      |                 |         |          |
|      |                 |         |          + Optional second argument named in_file2.
|      |                 |         |
|      |                 |         + Required first argument named in_file1
|      |                 |
|      |                 + An options placeholder.  This may be ommitted.  It must come before any arguments.
|      |
|      + An optional script name.  Omit this or use {self} to show $_SERVER['argv'][0].
|
+ The usage keyword.  This may be ommitted.

```

In this example, 1 argument is expected and the value provided will be assigned to the key "in\_file1" in the values object. An optional second argument will be assed to the key "in\_file2" if it is provided. And that's all. If a 3rd argument is provided it will not be assigned to a value and validation will fail.

### The Option Lines

[](#the-option-lines)

Here is how the first option line is interpreted:

```
-i, --id  specify an id (required)
|   |    |    |             |
|   |    |    |             + This makes the option required when validating.
|   |    |    |
|   |    |    + Help text.  This can be any text.
|   |    |
|   |    + This specifies that the option requires a value.  Unlike arguments, this is not used for the value name.
|   |
|   + This is a long option name.  It is not required.  If specified, this is used for the value name when arguments are parsed.
|
+ This is the short option name.  It is not required.  Values can be accessed using this shortcut.

```

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

4865d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b86e6a54873d5dd61d3682a3be00127af3b7b2b5c53eb070b160e29789d4c0d?d=identicon)[dweller](/maintainers/dweller)

---

Top Contributors

[![deweller](https://avatars.githubusercontent.com/u/51414?v=4)](https://github.com/deweller "deweller (28 commits)")

---

Tags

clicommand-lineoptioncommandgetopthelplineopt

### Embed Badge

![Health badge](/badges/deweller-cliopts/health.svg)

```
[![Health](https://phpackages.com/badges/deweller-cliopts/health.svg)](https://phpackages.com/packages/deweller-cliopts)
```

###  Alternatives

[phalcon/cli-options-parser

Command line arguments/options parser.

181.0M7](/packages/phalcon-cli-options-parser)[nategood/commando

PHP CLI Commando Style

8123.3M38](/packages/nategood-commando)[aura/cli

Provides the equivalent of request (Context) and response (Stdio) classes for a command line environment, including Getopt support.

1051.6M29](/packages/aura-cli)[splitbrain/php-cli

Easy command line scripts for PHP with opt parsing and color output. No dependencies

177817.2k28](/packages/splitbrain-php-cli)[inhere/console

php console library, provide console argument parse, console controller/command run, color style, user interactive, information show.

3477.4k12](/packages/inhere-console)[clue/commander

Finally a sane way to register available commands and arguments and match your command line in PHP.

16724.0k9](/packages/clue-commander)

PHPackages © 2026

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