PHPackages                             hhpack/getopt - 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. hhpack/getopt

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

hhpack/getopt
=============

Option parsing in Hack

1.7.1(7y ago)14653MITShell

Since Dec 28Pushed 7y agoCompare

[ Source](https://github.com/hhpack/getopt)[ Packagist](https://packagist.org/packages/hhpack/getopt)[ RSS](/packages/hhpack-getopt/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (5)Versions (29)Used By (3)

getopt
======

[](#getopt)

[![Latest Stable Version](https://camo.githubusercontent.com/346eba7365c6e9e2153fb7179121047094ee03ef223e86cee5fb64baeedc77d3/68747470733a2f2f706f7365722e707567782e6f72672f68687061636b2f6765746f70742f762f737461626c65)](https://packagist.org/packages/hhpack/getopt)[![CircleCI](https://camo.githubusercontent.com/05b68763a4cc640fa779b48509945da6f0069b112a6b403d3e201917fb028959/68747470733a2f2f636972636c6563692e636f6d2f67682f68687061636b2f6765746f70742f747265652f6d61737465722e7376673f7374796c653d737667)](https://circleci.com/gh/hhpack/getopt/tree/master)[![Dependency Status](https://camo.githubusercontent.com/d6a6bd54d03c4c070547678957034b2251f726f307ddc18145437cedcda64dba/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3536383463323537656234663437303033303030303432652f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/5684c257eb4f47003000042e)

Basic usage
-----------

[](#basic-usage)

The method of parsing command line arguments is as follows.
Define an option that takes no arguments, use the **on** function.
Define an option to take one argument, use the **take\_on** function.

```
use HHPack\Getopt as cli;

final class Options {
    public bool $help = false;
    public bool $version = false;
    public string $fileName = 'test';
}

$options = new Options();

$parser = cli\optparser([
    cli\take_on([ '-n', '--name' ], 'NAME', 'file name', ($name) ==> { $options->fileName = $name; }),
    cli\on([ '-h', '--help' ], 'display help message', () ==> { $options->help = true; }),
    cli\on([ '-v', '--version' ], 'display version', () ==> { $options->version = true; })
]);

$args = $parser->parse($argv);

if ($options->help === true) {
    echo 'help on', PHP_EOL;
}

if ($options->version === true) {
    echo 'version on', PHP_EOL;
}

if ($options->fileName !== 'test') {
    echo 'name = ', $fileName, PHP_EOL;
}
```

CLI Application
---------------

[](#cli-application)

If you want to create cli application, we recommend using **ArgumentParser**.
ArgumentParser implements an interface to display usage, program version.

```
use HHPack\Getopt as cli;
use HHPack\Getopt\App\{ ArgumentParser };

final class CliApplication
{

    private bool $help = false;
    private bool $version = false;
    private string $fileName = 'test';
    private ArgumentParser $argParser;

    public function __construct()
    {
        $this->argParser = cli\app('example', '1.0.0')
            ->description("This cli application is example.\n\n")
            ->usage("  {app.name} [OPTIONS]\n\n")
            ->options([
                cli\on(['-h', '--help'], 'display help message', () ==> {
                    $this->help = true;
                }),
                cli\on(['-v', '--version'], 'display version', () ==> {
                    $this->version = true;
                }),
                cli\take_on(['-n', '--name'], 'NAME', 'file name', ($name) ==> {
                    $this->fileName = $name;
                })
            ]);
    }

    public function run(Traversable $argv): void
    {
        $this->argParser->parse($argv);

        if ($this->help) {
            $this->argParser->displayHelp();
        } else if ($this->version) {
            $this->argParser->displayVersion();
        } else {
            echo "file name: ", $this->fileName, PHP_EOL;
        }
    }
}

(new CliApplication())->run($argv);
```

Run the test
------------

[](#run-the-test)

```
composer install
composer test

```

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity74

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

Recently: every ~85 days

Total

26

Last Release

2679d ago

Major Versions

0.9.0 → 1.0.02017-08-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/70c299d6d6015ee714954aa05e4d0e9c7b1d31318a5d7db5e9bb4e1f70f78afc?d=identicon)[holyshared](/maintainers/holyshared)

---

Top Contributors

[![holyshared](https://avatars.githubusercontent.com/u/167190?v=4)](https://github.com/holyshared "holyshared (99 commits)")

---

Tags

clihacklanghhvmoption-parsercliparserhhvmoptionhack

### Embed Badge

![Health badge](/badges/hhpack-getopt/health.svg)

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

###  Alternatives

[phalcon/cli-options-parser

Command line arguments/options parser.

181.1M12](/packages/phalcon-cli-options-parser)[kzykhys/ciconia

The Markdown parser for PHP5.4

35368.0k14](/packages/kzykhys-ciconia)[yoeunes/regex-parser

A PCRE regex parser with lexer, AST builder, validation, ReDoS analysis, and syntax highlighting. Zero runtime dependencies.

29122.7k8](/packages/yoeunes-regex-parser)[deweller/cliopts

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

1518.3k](/packages/deweller-cliopts)

PHPackages © 2026

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