{"id":16134066,"url":"https://github.com/noah2610/argumentparser","last_synced_at":"2025-07-26T10:35:32.243Z","repository":{"id":99629781,"uuid":"117722423","full_name":"Noah2610/ArgumentParser","owner":"Noah2610","description":"Simple Ruby command-line arguments/options parser.","archived":false,"fork":false,"pushed_at":"2018-05-23T22:11:10.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-06T15:51:11.183Z","etag":null,"topics":["argument-parser","cli","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/Noah2610.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":"2018-01-16T18:16:57.000Z","updated_at":"2023-02-16T02:26:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"fba174f3-8f65-438c-83b9-d25c27202906","html_url":"https://github.com/Noah2610/ArgumentParser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Noah2610/ArgumentParser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noah2610%2FArgumentParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noah2610%2FArgumentParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noah2610%2FArgumentParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noah2610%2FArgumentParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Noah2610","download_url":"https://codeload.github.com/Noah2610/ArgumentParser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noah2610%2FArgumentParser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267150480,"owners_count":24043473,"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-07-26T02:00:08.937Z","response_time":62,"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":["argument-parser","cli","ruby"],"created_at":"2024-10-09T22:47:10.028Z","updated_at":"2025-07-26T10:35:32.214Z","avatar_url":"https://github.com/Noah2610.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArgumentParser\nby Noah Rosenzweig  \n  \nA simple CLI arguments / options parser written in __Ruby__.\n\n---\n\n## Building Ruby Gem\nIf you like this script and think you will use it a bit,  \nyou can create and install a gem from it.  \nRun these commands in the root of the project:  \n```sh\n$ gem build ./argument_parser.gemspec\n$ gem install argument_parser\n```\n\n## Usage\nEither build a gem, as seen above, and `require 'argument_parser'`  \nin your script, or just copy the file `./lib/argument_parser.rb` and  \nrequire it like this `require_relative './PATH/TO/argument_parser'`.  \n  \nThis gem provides the class `ArgumentParser`.  \nCurrently it only contains a single method: `ArgumentParser.get_arguments`.  \nYou pass it a hash which contains your defined, valid arguments.  \nAn example usage script is included in this repo `./DEMO.rb`  \nin which there is a constant called `DEMO_VALID_ARGUMENTS`, that will show you  \nthe required syntax of the hash that is passed to the method.  \n  \nBasically you can define  \n__single-dash__ (-) options, __double-dash__ (--) options,  \nand __keywords__ (arguments without dashes).  \nKeywords are a bit experimental, but generally they are a list  \nof _keyword chains_ that are used from the command-line in order.  \n  \n### Example\n```ruby\n## Here the arguments you want the user to be able to use are defined.\nVALID_ARGUMENTS = {\n  ## Single option example (-a, -b):\n  single: {\n    help:        [['h','H'],               false],  # -h\n#   ^^^^            ^   ^                  ^^^^^\n# Identifier,  command-line option(s), accepts value?\n    version:     [['v','V'],               false]   # -v\n  },\n\n  ## Double option example (--foo, --bar):\n  double: {\n    help:        [['help'],                false],  # --help\n    version:     [['version'],             false],  # --version\n    status:      [['status'],              true]    # --status USER-INPUT\n  },\n\n  ## Keywords are positional, ignoring option positions\n  keywords: {\n    set:           [['set','define'],         ['var','constant'],       :INPUT,             :INPUTS]\n#   ^^^             ^^^^^^^^^^^^^^^^          ^^^^^^^^^^^^^^^^^^        ^^^^^^              ^^^^^^^\n# Main identifier   list of possible first    list of possible second   special symbol      special symbol,\n# of this           keywords, user can only   keywords                  that takes any      similar to :INPUT\n# keyword-chain     use one of these at the                             user input and      but takes an unlimited\n#                   first position                                      places it at this   amount of user input;\n#                   (ignoring options)                                  position            this should be the last\n#                                                                       (one argument)      keyword in the chain\n#                                                                                           (multiple arguments)\n  }\n}\n\n## Processed arguments returned in a formated hash\nuser_arguments = ArgumentParser.get_arguments VALID_ARGUMENTS\n\nputs \"Given Arguments:\"\nap user_arguments        # Print the user's arguments in a formated structure, using the awesome_print gem\n```\n```sh\n$ ./DEMO.rb -hv set --status FOO constant one --this -is --ignored two\nGiven Arguments:\n{\n   :options =\u003e {\n         :help =\u003e true,\n      :version =\u003e true,\n       :status =\u003e \"FOO\"\n  },\n  :keywords =\u003e {\n      :set =\u003e [\n          [0] \"set\",\n          [1] \"constant\",\n          [2] \"one\",\n          [2] \"two\"\n      ]\n  }\n}\n```\nThe above script won't just work if you copy/paste it, use the included  \n`./DEMO.rb` script, which uses the same configuration as above.  \n  \nYou can see that those three extra options (`--this -is --ignored`)  \nare ignored because they weren't defined in `VALID_ARGUMENTS`.  \nThis will probably change in the future, so the user gets feedback  \nabout their arguments being invalid.\n  \nWhen using the `./DEMO.rb` script it is recommended to have the gem  \n[`awesome_print`](https://github.com/awesome-print/awesome_print) installed; the gem _pretty prints_ ruby objects.  \nIt's _pretty awesome_.  \nInstall with `$ gem install awesome_print`.  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoah2610%2Fargumentparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoah2610%2Fargumentparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoah2610%2Fargumentparser/lists"}