{"id":43326446,"url":"https://github.com/jawher/parsopt","last_synced_at":"2026-02-01T23:12:18.723Z","repository":{"id":24210533,"uuid":"96889470","full_name":"jawher/parsopt","owner":"jawher","description":"The parsopt utility is used to quickly and easily accept and validate options and arguments in shell procedures. It's much more powerful and intuitive compared to getopt[s] as it handles short and long options, arguments, automatic help generation. etc.","archived":false,"fork":false,"pushed_at":"2024-06-01T05:51:29.000Z","size":55,"stargazers_count":8,"open_issues_count":4,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-06-19T18:12:16.764Z","etag":null,"topics":["cli","command-line","shell"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jawher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-11T12:14:54.000Z","updated_at":"2023-04-11T18:35:01.000Z","dependencies_parsed_at":"2022-07-27T04:46:10.337Z","dependency_job_id":"d614d527-a666-4f74-bacd-c4e451248ee0","html_url":"https://github.com/jawher/parsopt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jawher/parsopt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawher%2Fparsopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawher%2Fparsopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawher%2Fparsopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawher%2Fparsopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jawher","download_url":"https://codeload.github.com/jawher/parsopt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawher%2Fparsopt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28993994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T23:10:54.274Z","status":"ssl_error","status_checked_at":"2026-02-01T23:10:47.298Z","response_time":56,"last_error":"SSL_read: 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","command-line","shell"],"created_at":"2026-02-01T23:12:18.072Z","updated_at":"2026-02-01T23:12:18.718Z","avatar_url":"https://github.com/jawher.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parsopt : getopt[s] on steroids\n\n![CI](https://github.com/jawher/parsopt/workflows/CI/badge.svg)\n\nThe parsopt utility is used to quickly and easily accept and validate options and arguments in shell procedures.\nIt's much more powerful and intuitive compared to getopt[s] as it handles short and long options, arguments, automatic help generation. etc.\n\n## Quickstart\n\n### Install parsopt\n\nDownload the latest binary for your platform (Linux or Mac) from this page: https://github.com/jawher/parsopt/releases\n\nOr build it locally.\n\n### Use it\n\nTo showcase what parsopt does, we'll build a command line utility to convert between currencies.\n[fixer.io](http://fixer.io) will be used for the conversion part.\nAlso, this will use [HTTPie](https://github.com/jakubroztocil/httpie) (to perform the API calls) and [jq](https://stedolan.github.io/jq/) to parse the json responses.\n\n\nparsopt should be called from a shell function.\nPlace this code snippet in your `.bashrc`, `.zshrc` or whatever file is loaded by your shell:\n\n\n```bash\nfixer() {\n    eval \"$(parsopt '\n            app fixer Fixer API from the CLI\n\n            spec [OPTIONS] FROM [TO]\n\n            opt https  -s --use-https  :bool                      Use HTTPS\n            opt date   -d --date       =latest                    Use this date''s historical rate\n\n            arg from                                              The currency to convert from\n            arg to                     =EUR      $FIXER_TO        Return rates based on this currency\n        ' \"$@\")\"\n\n\n\n    protocol=\"http\"\n    [[ -n \"${https}\" ]] \u0026\u0026 protocol=\"https\"\n\n    http get \"${protocol}://api.fixer.io/${date:-latest}\" \"base==${to}\" \"symbols==${from}\" | jq \".rates | .${from}\"\n}\n\n```\n\nMake sure to open a new terminal window or tab (or to reload).\n\nIf you run:\n\n```\nfixer\n```\n\nYou'll get the following output:\n\n```\n$ fixer\nError: incorrect usage\n\nUsage: fixer [OPTIONS] FROM [TO]\n\nFixer API from the CLI\n\nArguments:\n  FROM=\"\"      The currency to convert from\n  TO=\"EUR\"     Return rates based on this currency ($FIXER_TO)\n\nOptions:\n  -s, --use-https=false   Use HTTPS\n  -d, --date=\"latest\"     Use this dates historical rate\n```\n\n(Same with `fixer -h` or `fixer --help`).\n\nYou just witnessed parsopt options/arguments validation and help message generation in action.\n\n\nIf you call it again with a valid syntax:\n\n```\nfixer USD EUR\n```\n\nWill proceed to call the fixer.io API and convert 1 USD to EUR.\n\n## Reference\n\n### Usage\nparsopt must be called from within a shell function, as follows:\n\n\n```bash\nfunction something() {\n    eval \"$(parsopt 'SPEC_STRING' \"$@\")\"\n\n    # Use the variables defined in SPEC_STRING\n}\n```\n\n### Spec\n\nThe `SPEC_STRING` is a multiline string, where every line is a directive.\n\nA directive has the following syntax:\n\n\n```\nDIRECTIVE_NAME VALUE VALUES*\n```\n\nparsopt supports the following directives:\n\n#### app\n\nOptional. Let's you set the name of the utility and the description to be shown in the usage message.\n\n**Syntax**\n\n```\napp APP_NAME DESC?\n```\n\n**Examples***\n\n```\napp fixer\n```\n\n```\napp fixer a CLI to convert between currencies\n```\n\n\n#### opt\n\nOptional. Let's you declare an option/flag.\n\n**Syntax**\n\n```\nopt VAR_NAME ('-'SHORT_NAME | '--'LONG_NAME)+ (':'TYPE) ('='DEFAULT_VALUE) ('$'ENV_VAR) DESC?\n```\n\nWhere:\n* `VAR_NAME`: the shell variable that will be populated from the option\n* `SHORT_NAME` and `LONG_NAME`: the option names (1 letter names for short names, more for long names), e.g. `-d`, `--debug`, etc.\n* `':'TYPE`: one of `:string`, `:int`, `:bool`, `:ints`, `:strings` Default is `:string`\n* `'='DEFAULT_VALUE`: the default value if the option is not set, e.g. `=/tmp/out`, `=true`\n* `'$'ENV_VAR`: set the value from the specified env var if the option is not set, e.g. `$HOME`\n\n**Examples***\n\n```\nopt debug -d --debug :bool $DEBUG_MODE =false Enable debug log\n```\n\n#### arg\n\nOptional. Let's you declare an argument.\n\n```\narg VAR_NAME (':'TYPE) ('='DEFAULT_VALUE) ('$'ENV_VAR) DESC?\n```\n\nWhere:\n* `VAR_NAME`: the shell variable that will be populated from the argument\n* `':'TYPE`: one of `:string`, `:int`, `:bool`, `:ints`, `:strings` Default is `:string`\n* `'='DEFAULT_VALUE`: the default value if the argument is not set, e.g. `=/tmp/out`, `=true`\n* `'$'ENV_VAR`: set the value from the specified env var if the argument is not set, e.g. `$HOME`\n\n**Examples***\n\n```\narg file_name $DEBUG_MODE Enable debug log\n```\n\n#### spec\n\nOptional. Let's you override the default spec string for the app generated by [mow.cli](https://github.com/jawher/mow.cli#spec).\n\nYou can refer to the:\n\n* options (declared using the opt directive) using their short or long names (e.g. -r, --verbose)\n* arguments (declared with the arg directive) by uppercasing their shell variable name\n\n\n```\nspec SPEC\n```\n\n**Examples***\n\n```\nspec [ -f | -d ] [-RHL] SRC DST...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjawher%2Fparsopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjawher%2Fparsopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjawher%2Fparsopt/lists"}