{"id":45138942,"url":"https://github.com/hhpack/getopt","last_synced_at":"2026-02-20T00:30:26.904Z","repository":{"id":56984220,"uuid":"48312150","full_name":"hhpack/getopt","owner":"hhpack","description":"Option parsing in Hack","archived":false,"fork":false,"pushed_at":"2019-04-15T03:30:42.000Z","size":128,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-05T07:22:19.495Z","etag":null,"topics":["cli","hacklang","hhvm","option-parser"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhpack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-20T08:06:20.000Z","updated_at":"2024-05-05T07:22:19.496Z","dependencies_parsed_at":"2022-08-21T12:50:36.774Z","dependency_job_id":null,"html_url":"https://github.com/hhpack/getopt","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/hhpack/getopt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fgetopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fgetopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fgetopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fgetopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhpack","download_url":"https://codeload.github.com/hhpack/getopt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fgetopt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29637407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T22:32:43.237Z","status":"ssl_error","status_checked_at":"2026-02-19T22:32:38.330Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","hacklang","hhvm","option-parser"],"created_at":"2026-02-20T00:30:26.037Z","updated_at":"2026-02-20T00:30:26.891Z","avatar_url":"https://github.com/hhpack.png","language":"Shell","readme":"# getopt\n\n[![Latest Stable Version](https://poser.pugx.org/hhpack/getopt/v/stable)](https://packagist.org/packages/hhpack/getopt)\n[![CircleCI](https://circleci.com/gh/hhpack/getopt/tree/master.svg?style=svg)](https://circleci.com/gh/hhpack/getopt/tree/master)\n[![Dependency Status](https://www.versioneye.com/user/projects/5684c257eb4f47003000042e/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5684c257eb4f47003000042e)\n\n## Basic usage\n\nThe method of parsing command line arguments is as follows.  \nDefine an option that takes no arguments, use the **on** function.  \nDefine an option to take one argument, use the **take_on** function.\n\n```hack\nuse HHPack\\Getopt as cli;\n\nfinal class Options {\n    public bool $help = false;\n    public bool $version = false;\n    public string $fileName = 'test';\n}\n\n$options = new Options();\n\n$parser = cli\\optparser([\n    cli\\take_on([ '-n', '--name' ], 'NAME', 'file name', ($name) ==\u003e { $options-\u003efileName = $name; }),\n    cli\\on([ '-h', '--help' ], 'display help message', () ==\u003e { $options-\u003ehelp = true; }),\n    cli\\on([ '-v', '--version' ], 'display version', () ==\u003e { $options-\u003eversion = true; })\n]);\n\n$args = $parser-\u003eparse($argv);\n\nif ($options-\u003ehelp === true) {\n    echo 'help on', PHP_EOL;\n}\n\nif ($options-\u003eversion === true) {\n    echo 'version on', PHP_EOL;\n}\n\nif ($options-\u003efileName !== 'test') {\n    echo 'name = ', $fileName, PHP_EOL;\n}\n```\n\n## CLI Application\n\nIf you want to create cli application, we recommend using **ArgumentParser**.  \nArgumentParser implements an interface to display usage, program version.\n\n```hack\nuse HHPack\\Getopt as cli;\nuse HHPack\\Getopt\\App\\{ ArgumentParser };\n\nfinal class CliApplication\n{\n\n    private bool $help = false;\n    private bool $version = false;\n    private string $fileName = 'test';\n    private ArgumentParser $argParser;\n\n    public function __construct()\n    {\n        $this-\u003eargParser = cli\\app('example', '1.0.0')\n            -\u003edescription(\"This cli application is example.\\n\\n\")\n            -\u003eusage(\"  {app.name} [OPTIONS]\\n\\n\")\n            -\u003eoptions([\n                cli\\on(['-h', '--help'], 'display help message', () ==\u003e {\n                    $this-\u003ehelp = true;\n                }),\n                cli\\on(['-v', '--version'], 'display version', () ==\u003e {\n                    $this-\u003eversion = true;\n                }),\n                cli\\take_on(['-n', '--name'], 'NAME', 'file name', ($name) ==\u003e {\n                    $this-\u003efileName = $name;\n                })\n            ]);\n    }\n\n    public function run(Traversable\u003cstring\u003e $argv): void\n    {\n        $this-\u003eargParser-\u003eparse($argv);\n\n        if ($this-\u003ehelp) {\n            $this-\u003eargParser-\u003edisplayHelp();\n        } else if ($this-\u003eversion) {\n            $this-\u003eargParser-\u003edisplayVersion();\n        } else {\n            echo \"file name: \", $this-\u003efileName, PHP_EOL;\n        }\n    }\n}\n\n(new CliApplication())-\u003erun($argv);\n```\n\n## Run the test\n\n\tcomposer install\n\tcomposer test\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhpack%2Fgetopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhpack%2Fgetopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhpack%2Fgetopt/lists"}