PHPackages                             appertly/cleopatra - 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. appertly/cleopatra

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

appertly/cleopatra
==================

Command line argument and option parser for Hack

0.1.1(10y ago)169[1 issues](https://github.com/appertly/cleopatra/issues)1MITC++

Since May 3Pushed 9y ago2 watchersCompare

[ Source](https://github.com/appertly/cleopatra)[ Packagist](https://packagist.org/packages/appertly/cleopatra)[ Docs](http://gitlab.com/appertly/cleopatra)[ RSS](/packages/appertly-cleopatra/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (2)Versions (3)Used By (1)

cleopatra
=========

[](#cleopatra)

A command line argument parser better than the builtin getopt for Hack/HHVM.

It got its name because it parses *CLI* *opt* ions.

[![Packagist](https://camo.githubusercontent.com/319768a3b649463ca9b2545dc11c2ea23abcfd1c5f9525051eca1e8bac9453f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6170706572746c792f636c656f70617472612e737667)](https://packagist.org/packages/appertly/cleopatra)[![Build Status](https://camo.githubusercontent.com/e291aebe0840e082af50681a5876c55f5194f17df29ebdd5188044f530e884b0/68747470733a2f2f7472617669732d63692e6f72672f6170706572746c792f636c656f70617472612e737667)](https://travis-ci.org/appertly/cleopatra)

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

[](#installation)

You can install this library using Composer:

```
$ composer require appertly/cleopatra
```

- The master branch (version 0.x) of this project requires HHVM 3.12 and has no dependencies.

Compliance
----------

[](#compliance)

Releases of this library will conform to [Semantic Versioning](http://semver.org).

Our code is intended to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), and [PSR-4](http://www.php-fig.org/psr/psr-4/). If you find any issues related to standards compliance, please send a pull request!

Features
--------

[](#features)

Users can specify command line options pretty much how you'd expect from typical shell conventions.

- Short options
    - Multiple short options can be bundled together (e.g. `-abcdef`)
    - Short options with required values can be specified either with a space or without (e.g. `-d2` or `-d 2`)
    - Short options with optional values must be specified without a space (e.g. `-d2`)
    - Short options without values can be bundled with those with values (e.g. `-abcd 2`)
- Long options
    - Long options with required values can be specified either with an equals sign or a space (e.g. `--foo bar` or `--foo="bar"`)
    - Long options with optional values must be specified with an equals sign (e.g. `--foo` or `--foo="bar"`)
- Normal arguments
    - Options can be specified in any order among regular arguments (e.g. `command -a value -b argument1 --opt="value" -c argument2 argument3`)
        - A real-world example of this: `aws --profile mine ec2 start-instances --instance-ids i-123456`
    - Arguments can be separated from all options with a double dash (e.g. `command -a value -xyz -- argument1 argument2 argument3`)
- Automatic help documentation

Usage
-----

[](#usage)

### Specification

[](#specification)

For simplicity, we stuck to a combination of [PHP's own `getopt` function](http://php.net/manual/en/function.getopt.php) and [Perl's Getopt::Long](http://perldoc.perl.org/Getopt/Long.html).

`[label][constraints][type]`

- The label contains aliases for the option, separated with a pipe (`|`), e.g. `l|length`
    - Labels must only consist of alphanumeric characters and the dash (e.g. `[a-zA-Z0-9\-]`)
- The constraint dictates how the option can be used
    - A plus (`+`) marks an option as incremental (e.g. `-vvv`)
    - A colon (`:`) marks an option as having a required value
    - Two colons (`::`) marks an option as non-required; a value can be specified with equals (e.g `--option="foo"`)
- The type can be used to specify how the argument value is evaluated
    - `s` = string, `i` = integer, `f` = float, `d` = `DateTimeImmutable`
    - A trailing at sign (`@`) will store multiple arguments in a `Vector` (e.g. `-d 1.txt -d 2.txt -d 3.txt`)

#### Examples

[](#examples)

```
l|length    = Boolean parameter with no argument (-l or --length)
v|verbose+  = Incremental option; value increased each time used
d|dir:      = Option with required value (-d stuff, --dir stuff)
d|dir::     = Option with optional value (--dir, --dir="stuff")
f|file:@    = Required option with multiple values (-f a.txt -f b.txt -f c.txt)
dir:s       = Required option will be evaluated as a string
dir::i      = Optional option will be evaluated as an integer
dir:f       = Option will be evaluated as a float
dir:d       = Option will be evaluated as a `DateTimeImmutable`
dir:s@      = Multiple options will result in a `Vector`

```

### Samples

[](#samples)

Here's a quick example.

The contents of test.hh:

```
parse($_SERVER['argv']);
$options = $cmd->getOptions(); // ImmMap
$arguments = $cmd->getArguments(); // ImmVector
if ($arguments->isEmpty() || $options->containsKey('help')) {
    echo $optionSet->getHelp(), PHP_EOL;
} else {
    echo "You executed: " . $cmd->getProgram(), PHP_EOL;
    echo "With options: " . json_encode($options), PHP_EOL;
    echo "With arguments: " . implode(", ", $arguments), PHP_EOL;
}
```

You run:

```
hhvm test.hh -qe foo -e bar --nice 123 run-tests -vvv -v --log=errors.log -v -xebaz src
```

You get:

```
You executed: test.hh
With options: {"q":true,"e":["foo","bar","baz"],"nice":123,"v":5,"log":"errors.log","x":true}
With arguments: run-tests, src

```

You run:

```
hhvm test.hh --help
```

You get:

```
  --help             Display this help
  --version          Shows version information
  -v --verbose       Enables verbose output; use multiple times to increase
                     verbosity
  -e --exclude       Excludes files and folders from processing
  --nice             Sets the process nice value
  --profile          Specifies which profile to use
  -q --quiet         Disables all output to stdout
  -x --experimental  Enables experimental features
  --log              Enables log output; default is syslog, but you can specify
                     a log filename

```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

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

Total

2

Last Release

3710d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/659262eac941ffe4795493834425fc9a2369c2c9df3cc565ed4194f1d37be934?d=identicon)[doublecompile](/maintainers/doublecompile)

---

Top Contributors

[![doublecompile](https://avatars.githubusercontent.com/u/4267230?v=4)](https://github.com/doublecompile "doublecompile (7 commits)")

---

Tags

clihhvmhackgetopt

### Embed Badge

![Health badge](/badges/appertly-cleopatra/health.svg)

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

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

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

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

4.7k357.7M10.6k](/packages/nunomaduro-collision)[nunomaduro/termwind

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

2.5k260.6M370](/packages/nunomaduro-termwind)[wp-cli/wp-cli

WP-CLI framework

5.1k18.5M394](/packages/wp-cli-wp-cli)[wp-cli/php-cli-tools

Console utilities for PHP

68227.8M374](/packages/wp-cli-php-cli-tools)[splitbrain/php-cli

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

178866.3k29](/packages/splitbrain-php-cli)

PHPackages © 2026

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