{"id":13878058,"url":"https://github.com/docopt/docopt.rb","last_synced_at":"2025-06-15T13:09:30.261Z","repository":{"id":3473804,"uuid":"4528791","full_name":"docopt/docopt.rb","owner":"docopt","description":"Parse command line arguments from nothing more than a usage message","archived":false,"fork":false,"pushed_at":"2023-04-09T18:40:08.000Z","size":88,"stargazers_count":460,"open_issues_count":7,"forks_count":45,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-11-17T14:57:22.634Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://docopt.org","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docopt.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,"governance":null}},"created_at":"2012-06-02T11:28:13.000Z","updated_at":"2024-10-19T18:28:49.000Z","dependencies_parsed_at":"2022-09-07T07:31:30.872Z","dependency_job_id":null,"html_url":"https://github.com/docopt/docopt.rb","commit_stats":{"total_commits":57,"total_committers":8,"mean_commits":7.125,"dds":0.6666666666666667,"last_synced_commit":"794c47d7cb62ca71d65086623a55881449bc2f9e"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/docopt/docopt.rb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docopt","download_url":"https://codeload.github.com/docopt/docopt.rb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.rb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259981475,"owners_count":22941149,"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-08-06T08:01:38.716Z","updated_at":"2025-06-15T13:09:30.235Z","avatar_url":"https://github.com/docopt.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"`docopt.rb` – command line option parser, that will make you smile\n===============================================================================\n\nThis is the ruby port of [`docopt`](https://github.com/docopt/docopt),\nthe awesome option parser written originally in python.\n\n\u003e New in version 0.5.0:\n\u003e\n\u003e Repeatable flags and commands are counted if repeated (a-la ssh `-vvv`).\n\u003e Repeatable options with arguments are accumulated into list.\n\nIsn't it awesome how `optparse` and `argparse` generate help messages\nbased on your code?!\n\n*Hell no!*  You know what's awesome?  It's when the option parser *is* generated\nbased on the beautiful help message that you write yourself!  This way\nyou don't need to write this stupid repeatable parser-code, and instead can\nwrite only the help message--*the way you want it*.\n\n`docopt` helps you create most beautiful command-line interfaces *easily*:\n\n```ruby\nrequire \"docopt\"\ndoc = \u003c\u003cDOCOPT\nNaval Fate.\n\nUsage:\n  #{__FILE__} ship new \u003cname\u003e...\n  #{__FILE__} ship \u003cname\u003e move \u003cx\u003e \u003cy\u003e [--speed=\u003ckn\u003e]\n  #{__FILE__} ship shoot \u003cx\u003e \u003cy\u003e\n  #{__FILE__} mine (set|remove) \u003cx\u003e \u003cy\u003e [--moored|--drifting]\n  #{__FILE__} -h | --help\n  #{__FILE__} --version\n\nOptions:\n  -h --help     Show this screen.\n  --version     Show version.\n  --speed=\u003ckn\u003e  Speed in knots [default: 10].\n  --moored      Moored (anchored) mine.\n  --drifting    Drifting mine.\n\nDOCOPT\n\nbegin\n  require \"pp\"\n  pp Docopt::docopt(doc)\nrescue Docopt::Exit =\u003e e\n  puts e.message\nend\n```\n\nBeat that! The option parser is generated based on the docstring above that is\npassed to `docopt` function.  `docopt` parses the usage pattern\n(`Usage: ...`) and option descriptions (lines starting with dash \"`-`\") and\nensures that the program invocation matches the usage pattern; it parses\noptions, arguments and commands based on that. The basic idea is that\n*a good help message has all necessary information in it to make a parser*.\n\nInstallation\n===============================================================================\n\nDocopt is available via rubygems:\n\n    gem install docopt\n\nAlternatively, you can just drop `lib/docopt.rb` file into your project--it is\nself-contained. [Get source on github](http://github.com/docopt/docopt.rb).\n\n`docopt` has been confirmed to work with 1.8.7p370 and 1.9.3p194. If you have\nnoticed it working (or not working) with an earlier version, please raise an\nissue and we will investigate support.\n\nAPI\n===============================================================================\n\n`Docopt` takes 1 required and 1 optional argument:\n\n- `doc` should be a string that\ndescribes **options** in a human-readable format, that will be parsed to create\nthe option parser.  The simple rules of how to write such a docstring\n(in order to generate option parser from it successfully) are given in the next\nsection. Here is a quick example of such a string:\n\n        Usage: your_program.rb [options]\n\n        -h --help     Show this.\n        -v --verbose  Print more text.\n        --quiet       Print less text.\n        -o FILE       Specify output file [default: ./test.txt].\n\n\nThe optional second argument contains a hash of additional data to influence\ndocopt. The following keys are supported: \n\n- `help`, by default `true`, specifies whether the parser should automatically\nprint the usage-message (supplied as `doc`) in case `-h` or `--help` options\nare encountered. After showing the usage-message, the program will terminate.\nIf you want to handle `-h` or `--help` options manually (as all other options),\nset `help=false`.\n\n- `version`, by default `nil`, is an optional argument that specifies the\nversion of your program. If supplied, then, if the parser encounters\n`--version` option, it will print the supplied version and terminate.\n`version` could be any printable object, but most likely a string,\ne.g. `'2.1.0rc1'`.\n\nNote, when `docopt` is set to automatically handle `-h`, `--help` and\n`--version` options, you still need to mention them in the options description\n(`doc`) for your users to know about them.\n\nThe **return** value is just a dictionary with options, arguments and commands,\nwith keys spelled exactly like in a help message\n(long versions of options are given priority). For example, if you invoke\nthe top example as::\n\n    naval_fate.rb ship Guardian move 100 150 --speed=15\n\nthe return dictionary will be::\n\n```ruby\n{\"ship\"=\u003etrue,\n \"new\"=\u003efalse,\n \"\u003cname\u003e\"=\u003e[\"Guardian\"],\n \"move\"=\u003etrue,\n \"\u003cx\u003e\"=\u003e\"100\",\n \"\u003cy\u003e\"=\u003e\"150\",\n \"--speed\"=\u003e\"15\",\n \"shoot\"=\u003efalse,\n \"mine\"=\u003efalse,\n \"set\"=\u003efalse,\n \"remove\"=\u003efalse,\n \"--moored\"=\u003efalse,\n \"--drifting\"=\u003efalse,\n \"--help\"=\u003efalse,\n \"--version\"=\u003efalse}\n```\n\nHelp message format\n===============================================================================\n\ndocopt.rb follows the docopt help message format.\nYou can find more details at\n[official docopt git repo](https://github.com/docopt/docopt#help-message-format)\n\n\nExamples\n-------------------------------------------------------------------------------\n\nWe have an extensive list of\n[examples](https://github.com/docopt/docopt.rb/tree/master/examples)\nwhich cover every aspect of functionality of `docopt`.  Try them out,\nread the source if in doubt.\n\nData validation\n-------------------------------------------------------------------------------\n\n`docopt` does one thing and does it well: it implements your command-line\ninterface.  However it does not validate the input data.  We are looking\nfor ruby validation libraries to make your option parsing experiene\neven more awesome!\nIf you've got any suggestions or think your awesome schema validation gem\nfits well with `docopt.rb`, open an issue on github and enjoy the eternal glory!\n\nContribution\n===============================================================================\n\nWe would *love* to hear what you think about `docopt.rb`.\nContribute, make pull requrests, report bugs, suggest ideas and discuss\n`docopt.rb` on\n[issues page](http://github.com/docopt/docopt.rb/issues).\n\nIf you want to discuss the original `docopt` reference,\npoint to [it's home](http://github.com/docopt/docopt) or\ndrop a line directly to vladimir@keleshev.com!\n\nPorting `docopt` to other languages\n===============================================================================\n\nDocopt is an interlinguistic (?) effort,\nand this is the ruby port of `docopt`.\nWe coordinate our efforts with docopt community and try our best to\nkeep in sync with the python reference.\n\nDocopt community *loves* to hear what you think about `docopt`, `docopt.rb`\nand other sister projects on docopt's\n[issues page](http://github.com/docopt/docopt/issues).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocopt%2Fdocopt.rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.rb/lists"}