{"id":16318121,"url":"https://github.com/scorphus/plugin-getopts","last_synced_at":"2025-05-13T17:16:08.519Z","repository":{"id":148200947,"uuid":"44420119","full_name":"scorphus/plugin-getopts","owner":"scorphus","description":"A Unix compliant implementation of getopts for fish.","archived":false,"fork":false,"pushed_at":"2015-10-17T04:52:57.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T20:28:09.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":false,"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/scorphus.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-10-17T02:15:46.000Z","updated_at":"2016-02-05T00:59:38.000Z","dependencies_parsed_at":"2023-04-10T09:17:37.124Z","dependency_job_id":null,"html_url":"https://github.com/scorphus/plugin-getopts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorphus%2Fplugin-getopts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorphus%2Fplugin-getopts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorphus%2Fplugin-getopts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scorphus%2Fplugin-getopts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scorphus","download_url":"https://codeload.github.com/scorphus/plugin-getopts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990503,"owners_count":21995776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-10T22:10:01.663Z","updated_at":"2025-05-13T17:16:08.496Z","avatar_url":"https://github.com/scorphus.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getopts\n\u003e friendly [`getopts`](http://en.wikipedia.org/wiki/Getopts) for [fish](https://fishshell.com) :fish:\n\n## Usage\n\n```fish\nAdd `getopts` to your `$fish_plugins` or import directly into your library via `import plugins/getopts`.\n```\n\n## Premise\nEvery utility / function needs to handle arguments. What usually happens is that every function does all the grunt work to parse `$argv` itself, and while some patterns do tend to recur, it's different almost every time. Enter fish `getopts`.\n\n## Synopsis\n  `getopts \u003coption string\u003e [ARGV...]`\n\n## Options\n#### `\u003coption string\u003e [:][\u003cletter\u003e][[:]\u003cword\u003e[:[^]]]`\n\nA string containing the option characters recognized by the utility calling `getopts`. If a `\u003cletter\u003e` or `\u003cword\u003e` ends in `:`, the option is expected to have an argument, which may be supplied separately or next to the option without spaces in the same string.\n\nTo indicate long options: `\u003cletter\u003e:\u003cword\u003e` and `\u003cword\u003e` are both valid option strings that will attempt to match `-\u003cletter\u003e` and `--\u003cword\u003e`.\n\nTo indicate _only_ short options, do not specify a `:\u003cword\u003e` after `\u003cletter\u003e`. For example, `a b` will match `-a` or `-b`.\n\nTo indicate optional arguments, use a `^` character after a `:` at the end of the option in the option string. For example `\u003cletter\u003e:^` and `\u003cletter\u003e:\u003cword\u003e:^` are both valid. Optional arguments should be supplied in the same string as the option and without spaces, e.g, `-\u003cletter\u003evalue` will correctly assign `value` as the argument to the the option `\u003cletter\u003e`, but `-\u003cletter\u003e` value, will parse `value` as the next argument in `\u003cARGV\u003e`.\n\nTo specify optional arguments using the option's long form, use a `=` character after the option: `--\u003cword\u003e=value`.\n\nUse a `:` at the beginning of the option string to enable strict mode. If enabled, `getopts` will exit with a status __\u003e 0__ if or when an unknown option is found. See [Diagnostics](#diagnostics).\n\n#### `\u003cARGV\u003e`\n\nList of options and operands to parse. `getopts` prints any matched options as well as available argument separated by a \\n to stdout and returns with a status of __0__ if there are still arguments; else returns with a status __\u003e 0__ if the end of the options is reached or an error occurs. See [Diagnostics](#diagnostics).\n\n#### Summary\n\n| Option String          |  Argument     | Short Style     | Long Style   |\n|:---------------:|:--------------:|------------------|:--------------------:|\n   `\"q:qqq:\"`          | Required   | `-q1` `-q 1`    | `--qqq 1`           |\n   `\"q:qqq:^\"`         | Optional    | `-q1`              | `--qqq=3`              |\n\n\n## Description\n`getopts` obtains options and their arguments from a list of parameters that, as indicated by \u003coption string\u003e, are single letters preceded by a `-` or words preceded by `--` and possibly followed by an argument value.\n\nfish `getopts` follows the specifications described in the [Utility Syntax Guidelines](http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html). The following is a summary of the features:\n\n+ Short options; single letters preceded by `-`, and long options; words preceded by `--`, are both supported.\n\n+ Single letters may be grouped. `-abc` → `-a -b -c`\n\n+ Options required to take an argument can specify the argument either in the same string as the option or separated from the by a space. (1) `-a argument`, (2) `-aargument`\n\n+ Options that can take an argument optionally shall specify the argument in the same string as the option argument if in short option style: `-aargument`, or separated by a `=` if in long form: `--long-form=argument`. If a blank space is used, the following argument will be treated independently.\n\n+ Options can appear multiple times in the same argument list. `getopts` will print every match sequentially on each call, and should default to the short form of the option if available.\n\n+ The option delimiter `:` and optional argument character `^` shall not be used as an option.\n\n+ `getopts` will return the remaining operands when the end of the options is reached, i.e, a `--` argument that is not an option is found, or an argument that does not begin with `-` is found.\n\n## Environment Variables\nThe following environment variables are used internally by `getopts`. These variables are erased from memory when the function returns 1.\n\n+ `__getopts_optstr` _Whitespace trimmed option string._\n\n+ `__getopts_argv` _Preprocessed copy of arguments._\n\n+ `__getopts_index` _Index of the next argument to handle._\n\n+ `__getopts_required` _List of options with required arguments._\n\n+ `__getopts_optional` _List of options with optional arguments._\n\n\n## \u003ca name=\"diagnostics\"\u003e\u003c/a\u003eDiagnostics\nPossible exit status values are:\n\n+ __0__: An argument formed like an option was found. This causes getopts to print the option short-style and its argument if available. If strict-mode is enabled setting the first character of the option to `:`, an unknown option will cause `getopts` to fail. See below.\n\n+ __1__: The end of the options was reached. Remaining operands are also sent to stdout.\n\n+ __2__: An option argument was missing.\n\n+ __3__: An unknown option was found. Only if strict-mode is enabled.\n\n## Examples\n```fish\n  function my_utility\n    while set optarg (getopts \"l:long x: o:optional:^\" $argv)\n      switch $optarg[1]\n        case l\n          echo handle `-l --long`\n        case x\n          echo handle `-x` w/ argument `$optarg[2]`\n        case o\n          echo handle `-o --optional` w/ optional argument `$optarg[2]`\n        case \\*\n          echo unknown option `$optarg[1]`\n      end\n    end\n    echo -n operands: \"`$optarg`\"\n  end\n```\n\n## Links\n+ [UNIX Utility Conventions](http://pubs.opengroup.org/onlinepubs/7908799/xbd/utilconv.html)\n\n## License\n[MIT](http://opensource.org/licenses/MIT) © [Jorge Bucaran](http://bucaran.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscorphus%2Fplugin-getopts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscorphus%2Fplugin-getopts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscorphus%2Fplugin-getopts/lists"}