{"id":28726884,"url":"https://github.com/docopt/docopt.d","last_synced_at":"2026-01-30T08:03:38.753Z","repository":{"id":17824806,"uuid":"20726751","full_name":"docopt/docopt.d","owner":"docopt","description":null,"archived":false,"fork":false,"pushed_at":"2017-01-01T13:46:57.000Z","size":78,"stargazers_count":30,"open_issues_count":3,"forks_count":8,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-05-09T19:19:24.260Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"D","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/docopt.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-11T13:46:53.000Z","updated_at":"2023-12-19T21:58:44.000Z","dependencies_parsed_at":"2022-08-31T22:01:50.338Z","dependency_job_id":null,"html_url":"https://github.com/docopt/docopt.d","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/docopt/docopt.d","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docopt","download_url":"https://codeload.github.com/docopt/docopt.d/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.d/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":"2025-06-15T13:09:28.235Z","updated_at":"2026-01-30T08:03:33.719Z","avatar_url":"https://github.com/docopt.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"``docopt`` creates *beautiful* command-line interfaces\n======================================================================\n\n.. image:: https://travis-ci.org/docopt/docopt.d.svg?branch=master\n\nYou know what's awesome?  It's when the option parser *is*\ngenerated based on the beautiful help message that you write yourself!\nThis way you don't need to write this stupid repeatable parser-code,\nand instead can write only the help message--*the way you want it*.\n\n**docopt** helps you create most beautiful command-line interfaces\n*easily*:\n\n.. code:: d\n\n   import std.stdio;\n\n   import docopt;\n\n   int main(string[] args) {\n       \n       auto doc = \"Naval Fate.\n\n       Usage:\n         naval_fate ship new \u003cname\u003e...\n         naval_fate ship \u003cname\u003e move \u003cx\u003e \u003cy\u003e [--speed=\u003ckn\u003e]\n         naval_fate ship shoot \u003cx\u003e \u003cy\u003e\n         naval_fate mine (set|remove) \u003cx\u003e \u003cy\u003e [--moored|--drifting]\n         naval_fate -h | --help\n         naval_fate --version\n\n       Options:\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       \";\n\n       auto arguments = docopt.docopt(doc, args[1..$], true, \"Naval Fate 2.0\");\n       writeln(arguments);\n       return 0;\n    }\n\n\n\nBeat that! The option parser is generated based on the docstring above\nthat is passed to ``docopt`` function.  ``docopt`` parses the usage\npattern (``\"Usage: ...\"``) and option descriptions (lines starting\nwith dash \"``-``\") and ensures that the program invocation matches the\nusage pattern; it parses options, arguments and commands based on\nthat. The basic idea is that *a good help message has all necessary\ninformation in it to make a parser*.\n\nD port details\n======================================================================\n\nThis is a port of docopt.py, \n`http://github.com/docopt/docopt \u003chttp://github.com/docopt/docopt\u003e`_ \nwhich has all features of the latest version. \n\nInstallation\n======================================================================\n\nUse `dub \u003chttp://code.dlang.org\u003e`_.\n\n.. code:: json\n\n    {\n\t    \"dependencies\": {\n\t\t    \"docopt\": \"\u003e=0.6.1\"\n\t    }\n    }\n\n\n**docopt** is tested with D 2.070.\n\nTesting\n======================================================================\n\nYou can run unit tests using the command:\n\n    make test\n\n\nAPI\n======================================================================\n\n.. code:: d\n\n    import docopt;\n\n.. code:: d\n\n   public ArgValue[string] docopt(string doc, string[] argv,\n                                  bool help = false,\n                                  string vers = null,\n                                  bool optionsFirst = false)\n\n\n``docopt`` takes 2 required and 3 optional arguments:\n\n- ``doc`` is a \n  string that contains a **help message** that will be parsed to\n  create the option parser.  The simple rules of how to write such a\n  help message are given in next sections.  Here is a quick example of\n  such a string:\n\n.. code:: d\n\n    string doc = \"Usage: my_program [-hso FILE] [--quiet | --verbose] [INPUT ...]\n\n    -h --help    show this\n    -s --sorted  sorted output\n    -o FILE      specify output file [default: ./test.txt]\n    --quiet      print less text\n    --verbose    print more text\n\n    \";\n\n- ``argv`` is an command-line argument array; most likely taken from\n  the ``string[] args`` passed to your ``main``. Since the program\n  name is in ``args[0]``, you should passed ``args[1..$]``.\n  Alternatively you can supply an array of strings like\n  ``['--verbose', '-o', 'hai.txt']``.\n\n- ``help``, by default ``true``, specifies whether the parser should\n  automatically print the help message (supplied as ``doc``) and\n  terminate, in case ``-h`` or ``--help`` option is encountered\n  (options should exist in usage pattern, more on that below). If you\n  want to handle ``-h`` or ``--help`` options manually (as other\n  options), set ``help=false``.\n\n- ``version``, by default ``null``, is an optional argument that\n  specifies the version of your program. If supplied, then, (assuming\n  ``--version`` option is mentioned in usage pattern) when parser\n  encounters the ``--version`` option, it will print the supplied\n  version and terminate.  ``version`` is a string,\n  e.g. ``\"2.1.0rc1\"``.\n\n    Note, when ``docopt`` is set to automatically handle ``-h``,\n    ``--help`` and ``--version`` options, you still need to mention\n    them in usage pattern for this to work. Also, for your users to\n    know about them.\n\n- ``optionsFirst``, by default ``false``.  If set to ``true`` will\n  disallow mixing options and positional argument.  I.e. after first\n  positional argument, all arguments will be interpreted as positional\n  even if they look like options.  This can be used for strict\n  compatibility with POSIX, or if you want to dispatch your arguments\n  to other programs.\n\nThe **return** value is a simple associative array with options, arguments\nand commands as keys, spelled exactly like in your help message.  Long\nversions of options are given priority. For example, if you invoke the\ntop example as::\n\n    naval_fate ship Guardian move 100 150 --speed=15\n\nthe return dictionary will be:\n\n.. code:: s\n\n    ['--drifting': false,    'mine': false,\n     '--help': false,        'move': true,\n     '--moored': false,      'new': false,\n     '--speed': 15,          'remove': false,\n     '--version': false,     'set': false,\n     '\u003cname\u003e': ['Guardian'], 'ship': true,\n     '\u003cx\u003e': 100,             'shoot': false,\n     '\u003cy\u003e': 150]\n\nHelp message format\n======================================================================\n\nHelp message consists of 2 parts:\n\n- Usage pattern, e.g.::\n\n    Usage: my_program [-hso FILE] [--quiet | --verbose] [INPUT ...]\n\n- Option descriptions, e.g.::\n\n    -h --help    show this\n    -s --sorted  sorted output\n    -o FILE      specify output file [default: ./test.txt]\n    --quiet      print less text\n    --verbose    print more text\n\nTheir format is described below; other text is ignored.\n\nUsage pattern format\n----------------------------------------------------------------------\n\n**Usage pattern** is a substring of ``doc`` that starts with\n``usage:`` (case *insensitive*) and ends with a *visibly* empty line.\nMinimum example:\n\n.. code:: d\n\n    auto doc = \"Usage: my_program\n\n    \";\n\nThe first word after ``usage:`` is interpreted as your program's name.\nYou can specify your program's name several times to signify several\nexclusive patterns:\n\n.. code:: d\n\n    auto doc = \"\n       Usage: my_program FILE\n              my_program COUNT FILE\n\n    \";\n\nEach pattern can consist of the following elements:\n\n- **\u003carguments\u003e**, **ARGUMENTS**. Arguments are specified as either\n  upper-case words, e.g. ``my_program CONTENT-PATH`` or words\n  surrounded by angular brackets: ``my_program \u003ccontent-path\u003e``.\n- **--options**.  Options are words started with dash (``-``), e.g.\n  ``--output``, ``-o``.  You can \"stack\" several of one-letter\n  options, e.g. ``-oiv`` which will be the same as ``-o -i -v``. The\n  options can have arguments, e.g.  ``--input=FILE`` or ``-i FILE`` or\n  even ``-iFILE``. However it is important that you specify option\n  descriptions if you want your option to have an argument, a default\n  value, or specify synonymous short/long versions of the option (see\n  next section on option descriptions).\n- **commands** are words that do *not* follow the described above\n  conventions of ``--options`` or ``\u003carguments\u003e`` or ``ARGUMENTS``,\n  plus two special commands: dash \"``-``\" and double dash \"``--``\"\n  (see below).\n\nUse the following constructs to specify patterns:\n\n- **[ ]** (brackets) **optional** elements.  e.g.: ``my_program\n  [-hvqo FILE]``\n- **( )** (parens) **required** elements.  All elements that are *not*\n  put in **[ ]** are also required, e.g.: ``my_program\n  --path=\u003cpath\u003e \u003cfile\u003e...`` is the same as ``my_program\n  (--path=\u003cpath\u003e \u003cfile\u003e...)``.  (Note, \"required options\" might be not\n  a good idea for your users).\n- **|** (pipe) **mutually exclusive** elements. Group them using **(\n  )** if one of the mutually exclusive elements is required:\n  ``my_program (--clockwise | --counter-clockwise) TIME``. Group\n  them using **[ ]** if none of the mutually-exclusive elements are\n  required: ``my_program [--left | --right]``.\n- **...** (ellipsis) **one or more** elements. To specify that\n  arbitrary number of repeating elements could be accepted, use\n  ellipsis (``...``), e.g.  ``my_program FILE ...`` means one or\n  more ``FILE``-s are accepted.  If you want to accept zero or more\n  elements, use brackets, e.g.: ``my_program [FILE ...]``. Ellipsis\n  works as a unary operator on the expression to the left.\n- **[options]** (case sensitive) shortcut for any options.  You can\n  use it if you want to specify that the usage pattern could be\n  provided with any options defined below in the option-descriptions\n  and do not want to enumerate them all in usage-pattern.\n- \"``[--]``\". Double dash \"``--``\" is used by convention to separate\n  positional arguments that can be mistaken for options. In order to\n  support this convention add \"``[--]``\" to your usage patterns.\n- \"``[-]``\". Single dash \"``-``\" is used by convention to signify that\n  ``stdin`` is used instead of a file. To support this add \"``[-]``\"\n  to your usage patterns. \"``-``\" acts as a normal command.\n\nIf your pattern allows to match argument-less option (a flag) several\ntimes::\n\n    Usage: my_program [-v | -vv | -vvv]\n\nthen number of occurrences of the option will be counted. I.e.\n``args[\"-v\"]`` will be ``2`` if program was invoked as ``my_program\n-vv``. Same works for commands.\n\nIf your usage patterns allows to match same-named option with argument\nor positional argument several times, the matched arguments will be\ncollected into a list::\n\n    Usage: my_program \u003cfile\u003e \u003cfile\u003e --path=\u003cpath\u003e...\n\nI.e. invoked with ``my_program file1 file2 --path=./here\n--path=./there`` the returned dict will contain ``args[\"\u003cfile\u003e\"] ==\n[\"file1\", \"file2\"]`` and ``args[\"--path\"] == [\"./here\", \"./there\"]``.\n\n\nOption descriptions format\n----------------------------------------------------------------------\n\n**Option descriptions** consist of a list of options that you put\nbelow your usage patterns.\n\nIt is necessary to list option descriptions in order to specify:\n\n- synonymous short and long options,\n- if an option has an argument,\n- if option's argument has a default value.\n\nThe rules are as follows:\n\n- Every line in ``doc`` that starts with ``-`` or ``--`` (not counting\n  spaces) is treated as an option description, e.g.::\n\n    Options:\n      --verbose   # GOOD\n      -o FILE     # GOOD\n    Other: --bad  # BAD, line does not start with dash \"-\"\n\n- To specify that option has an argument, put a word describing that\n  argument after space (or equals \"``=``\" sign) as shown below. Follow\n  either \u003cangular-brackets\u003e or UPPER-CASE convention for options'\n  arguments.  You can use comma if you want to separate options. In\n  the example below, both lines are valid, however you are recommended\n  to stick to a single style.::\n\n    -o FILE --output=FILE       # without comma, with \"=\" sign\n    -i \u003cfile\u003e, --input \u003cfile\u003e   # with comma, without \"=\" sing\n\n- Use two spaces to separate options with their informal description::\n\n    --verbose More text.   # BAD, will be treated as if verbose option had\n                           # an argument \"More\", so use 2 spaces instead\n    -q        Quit.        # GOOD\n    -o FILE   Output file. # GOOD\n    --stdout  Use stdout.  # GOOD, 2 spaces\n\n- If you want to set a default value for an option with an argument,\n  put it into the option-description, in form ``[default:\n  \u003cmy-default-value\u003e]``::\n\n    --coefficient=K  The K coefficient [default: 2.95]\n    --output=FILE    Output file [default: test.txt]\n    --directory=DIR  Some directory [default: ./]\n\n- If the option is not repeatable, the value inside ``[default: ...]``\n  will be interpreted as string.  If it *is* repeatable, it will be\n  split into a list on whitespace::\n\n    Usage: my_program [--repeatable=\u003carg\u003e --repeatable=\u003carg\u003e]\n                      [--another-repeatable=\u003carg\u003e]...\n                      [--not-repeatable=\u003carg\u003e]\n\n    // will be [\"./here\", \"./there\"]\n    --repeatable=\u003carg\u003e          [default: ./here ./there]\n\n    // will be [\"./here\"]\n    --another-repeatable=\u003carg\u003e  [default: ./here]\n\n    // will be \"./here ./there\", because it is not repeatable\n    --not-repeatable=\u003carg\u003e      [default: ./here ./there]\n\nExamples\n----------------------------------------------------------------------\n\nWe have an extensive list of `examples\n\u003chttps://github.com/rwtolbert/docopt.d/tree/master/examples\u003e`_ which cover\nevery aspect of functionality of **docopt**.  Try them out, read the\nsource if in doubt.\n\nSubparsers, multi-level help and *huge* applications (like git)\n----------------------------------------------------------------------\n\nIf you want to split your usage-pattern into several, implement\nmulti-level help (with separate help-screen for each subcommand),\nwant to interface with existing scripts that don't use **docopt**, or\nyou're building the next \"git\", you will need the ``optionsFirst``\nparameter (described in API section above). To get you started quickly\nwe implemented a subset of git command-line interface as an example:\n`examples/git\n\u003chttps://github.com/rwtolbert/docopt.d/tree/master/examples/git\u003e`_\n\n\nChangelog\n======================================================================\n\n**docopt** follows `semantic versioning \u003chttp://semver.org\u003e`_.  The\nfirst release with stable API will be 1.0.0 (soon).  Until then, you\nare encouraged to specify explicitly the version in your dependency\ntools, e.g.::\n\n\n- 0.6.1-b.1 Initial release in D.\n- 0.6.1-b.2 Updates for D 2.067\n- 0.6.1-b.3 Updates for D 2.067.1, gdc and ldc2\n- 0.6.1-b.5 Updates for D 2.070\n- 0.6.1-b.6 Updates for D 2.072\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocopt%2Fdocopt.d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.d/lists"}