{"id":17964803,"url":"https://github.com/sirwumpus/erlang-getopt","last_synced_at":"2025-10-11T22:18:47.865Z","repository":{"id":57493749,"uuid":"81564462","full_name":"SirWumpus/erlang-getopt","owner":"SirWumpus","description":"POSIX style command-line option parsing.","archived":false,"fork":false,"pushed_at":"2023-01-03T20:42:09.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-21T02:27:18.146Z","etag":null,"topics":["command-line","erlang","posix"],"latest_commit_sha":null,"homepage":"","language":"Erlang","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/SirWumpus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-10T12:44:49.000Z","updated_at":"2022-05-18T21:29:39.000Z","dependencies_parsed_at":"2023-02-01T09:46:08.107Z","dependency_job_id":null,"html_url":"https://github.com/SirWumpus/erlang-getopt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/SirWumpus/erlang-getopt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-getopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-getopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-getopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-getopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SirWumpus","download_url":"https://codeload.github.com/SirWumpus/erlang-getopt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-getopt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009047,"owners_count":26084547,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["command-line","erlang","posix"],"created_at":"2024-10-29T12:08:46.411Z","updated_at":"2025-10-11T22:18:47.830Z","avatar_url":"https://github.com/SirWumpus.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"egetopt\n=======\n\nParse a list of strings according to POSIX command-line option and argument rules.  There is no support for GNU long option names, see [jcomellas/getopt](https://github.com/jcomellas/getopt) instead.\n\n\nData Types\n----------\n\n* Args = [ string() ]\n* ArgsRemaining = [ string() ]\n* Glyph = alpha() | digit()\n* MapSpec = #{ Glyph =\u003e { OptName, OptType } }\n* OptName = atom()\n* OptSpec = MapSpec | StringSpec | TupleSpec\n* OptType = count | flag | list | param\n* Map = #{FlagName =\u003e true, CountName =\u003e integer() ParamName =\u003e string(), ListName =\u003e [ stringN(), ..., string1() ] }\n* TupleSpec = [ { Glyph, OptType, OptName } ]\n* StringSpec = string()\n\n\nExports\n-------\n\n### egetopt:parse(Args, OptSpec) -\u003e {ok, Plist, ArgsRemaining} | {error, Reason, Glyph}\n\nParse list of strings according to POSIX command-line option and argument rules.  An argument that starts with a leading hyphen (-) followed by a single character, \"-f\".  An option is either an option-flag, \"-f\", or option-parameter, \"-x param\".  Option-flags can appear together in any order as a list, \"-hfg\"; an option-parameter can appear at the end of list of option-flags, \"-hfgx param\" or \"-hfgxparam\".  Options can appear in any order and be repeated until a \"--\" argument is seen, which indicates the remainder are only arguments.\n\nThe `OptSpec` can be one of three formats:\n\n* The `StringSpec`, similar to `getopt(3)`, is a string consisting of individual characters for option-flags and characters followed by a colon `:` to indicate an option-parameter is to follow.  As an extension, characters followed by a hash `#` for option-count and characters followed by semi-colon `;` for option-list.  The `OptName` used in the returned map is the option glyph prefixed by `opt_`.\n\n* The `MapSpec` is a map keyed by option glyph, whos value is a tuple with `{OptName, OptType}`.\n\n* The `TupleSpec` is a tuple list of `{Glyph, OptType, OptName}`.\n\nThe `Plist` returned is keyed by `OptName`.  Each option's value varies according to the `OptType` given by `OptSpec`: `flag` simple sets the option to `true`; `count` for the number of times an option flag is repeated; `param` sets an option to the last seen parameter string; and `list` set an option to a list of parameter strings collected in reverse order.\n\n### egetopt:to_map(Args, OptSpec) -\u003e {ok, Map, ArgsRemaining} | {error, Reason, Glyph}\n\nSame as `egetopt:parse/2`, returning a `Map` in place of `Plist` for an `ok` result.\n\n### opts:to_map(Args, OptSpec) -\u003e {ok, Map, ArgsRemaining} | {error, Reason, Glyph}\n\nSimilar to `egetopt:to_map/2`, with the side-effect of saving the parsed options as an `ets` table.\n\n### opts:get(OptName) -\u003e Value | undefined\n\nGet the `OptName` from the `ets` table returning a value.\n\n### opts:get(OptName, Default) -\u003e Value | Default\n\nGet the `OptName` from the `ets` table returning a value; otherwise `Default`.\n\n### opts:set(OptName, OptArg) -\u003e true\n\nSet the value of an `OptName` in the `ets` table.\n\n\nExample\n-------\n\n```\n-module(example).\n-export([main/1]).\n\nmain(Args) -\u003e\n        case egetopt:parse(Args, \"ab#c:d;\") of\n        {ok, Options, ArgsN} -\u003e\n                io:format(\"parsed ~p, remaining ~p~n\", [Options, ArgsN]);\n        {error, Reason, Opt} -\u003e\n                io:format(\"~s -~c~n\", [Reason, Opt])\n        end.\n```\n\n```\n$ example1 -aa -b -bb -cfoo -done -c replace -d two hey you\nparsed #{opt_a =\u003e true,opt_b =\u003e 3,opt_c =\u003e \"replace\",\nopt_d =\u003e [\"two\",\"one\"]}, remaining [\"hey\",\"you\"]\n\n$ example1 -aa -b -bb -cfoo -done -- -c replace -d two hey you\nparsed #{some_a =\u003e true,some_b =\u003e 3,some_c =\u003e \"foo\",some_d =\u003e [\"one\"]},\nremaining [\"-c\", \"replace\", \"-d\", \"two\", \"hey\", \"you\"]\n\n$ example1 -a -b -x -y\nunknown option -x\nusage: example [-a][-b...][-c param][-d item] ...\n-a              set flag true\n-b              count repeated occurences\n-c param        set parameter\n-d item         add item to list\n\n$ example1 -a -c\nmissing parameter -c\nusage: example [-a][-b...][-c param][-d item] ...\n-a              set flag true\n-b              count repeated occurences\n-c param        set parameter\n-d item         add item to list\n```\n\n`example1` uses a `getopt(3)` style option string specification with the extensions for count and list types.\n`example2` uses the map specification with different option names.\n`example3` uses the tuple-list specification with different option names.\n\n\nCopyright\n---------\n\nCopyright 2017, 2022 by Anthony Howe.  All rights reserved.\n\n\nMIT License\n-----------\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirwumpus%2Ferlang-getopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirwumpus%2Ferlang-getopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirwumpus%2Ferlang-getopt/lists"}