{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Utilities" ], "description": "# `docopt-ng` creates *magic* command-line interfaces\n\n[![image](https://travis-ci.org/bazaar-projects/docopt-ng.svg?branch=master)](https://travis-ci.org/bazaar-projects/docopt-ng)\n\n[![codecov](https://codecov.io/gh/bazaar-projects/docopt-ng/branch/master/graph/badge.svg)](https://codecov.io/gh/bazaar-projects/docopt-ng)\n\n[![image](https://img.shields.io/pypi/v/docopt-ng.svg)](https://pypi.python.org/pypi/docopt-ng)\n\n## CHANGELOG\n\n#### New in version 0.7.2:\n\n> - Complete MyPy typehints - ZERO errors.\n> Required refactoring class implementations, adding typing stubs, but not changing tests. :)\n> - 100% code coverage. Required the addition of a few tests.\n> Removed unused codepaths. Tagged typing stubs `pragma: no cover` as they are definitionally exercised.\n\n#### New in version 0.7.1:\n\n> - Add `magic()` and `magic_docopt()` aliases for `docopt()` allowing easier use of new features.\n\n#### New in version 0.7.0:\n\n> - \"MORE MAGIC\"\n> - First argument is now optional - `docopt()` will look for `__doc__` defined in parent scopes.\n> - Dot access is supported on resulting `arguments` object,\n> ignoring angle brackets and leading dashes.\n> - `more_magic` parameter added to `docopt()` defaults False.\n> - If `more_magic` enabled, `arguments` variable created and populated\n> in calling scope with results.\n> - If `more_magic` enabled, fuzzy (levenshtein) autocorrect enabled for long-args.\n> - Lots of typehints.\n> - README moved to Markdown.\n\n#### New in version 0.6.3:\n\n> - Catch up on \\~two years of pull requests.\n> - Fork [docopt](https://github.com/docopt/docopt) to\n> [docopt-ng](https://github.com/bazaar-projects/docopt-ng).\n> - Add levenshtein based autocorrect from\n> [string-dist](https://github.com/obulkin/string-dist).\n> - Add better debug / error messages.\n> - Linting (via [black](https://github.com/ambv/black) and\n> [flake8](https://gitlab.com/pycqa/flake8)).\n\n#### New in version 0.6.2:\n\n> - Bugfixes\n>\n#### New in version 0.6.1:\n>\n> - Fix issue [\\#85](https://github.com/docopt/docopt/issues/85) which\n> caused improper handling of `[options]` shortcut if it was present\n> several times.\n>\n#### New in version 0.6.0:\n>\n> - New argument `options_first`, disallows interspersing options and\n> arguments. If you supply `options_first=True` to `docopt`, it will\n> interpret all arguments as positional arguments after first\n> positional argument.\n> - If option with argument could be repeated, its default value will\n> be interpreted as space-separated list. E.g. with\n> `[default: ./here ./there]` will be interpreted as\n> `['./here', './there']`.\n\n**docopt-ng** helps you create beautiful command-line interfaces *magically*:\n\n``` {.sourceCode .python}\n\"\"\"Naval Fate.\n\nUsage:\n naval_fate.py ship new ...\n naval_fate.py ship move [--speed=]\n naval_fate.py ship shoot \n naval_fate.py mine (set|remove) [--moored | --drifting]\n naval_fate.py (-h | --help)\n naval_fate.py --version\n\nOptions:\n -h --help Show this screen.\n --version Show version.\n --speed= Speed in knots [default: 10].\n --moored Moored (anchored) mine.\n --drifting Drifting mine.\n\n\"\"\"\nfrom docopt import docopt\n\n\nif __name__ == '__main__':\n arguments = docopt(__doc__, version='Naval Fate 2.0')\n print(arguments)\n```\n\nBeat that! The option parser is generated based on the docstring above\nthat is passed to `docopt` function. `docopt` parses the usage pattern\n(`\"Usage: ...\"`) and option descriptions (lines starting with dash\n\"`-`\") and ensures that the program invocation matches the usage\npattern; it parses options, arguments and commands based on that. The\nbasic idea is that *a good help message has all necessary information in\nit to make a parser*.\n\nAlso, [PEP 257](http://www.python.org/dev/peps/pep-0257/) recommends\nputting help message in the module docstrings.\n\n# Installation\n\nUse [pip](http://pip-installer.org) or easy\\_install:\n\n pip install docopt-ng\n\nAlternatively, you can just drop `docopt.py` file into your project--it\nis self-contained.\n\n**docopt-ng** is tested with Python 3.6 and 3.7.\n\n# Testing\n\nYou can run unit tests using the command:\n\n> python setup.py test\n\n# API\n\n``` {.sourceCode .python}\nfrom docopt import docopt\n```\n\n``` {.sourceCode .python}\ndocopt(docstring=None, argv=None, help=True, version=None, options_first=False, more_magic=False)\n```\n\n`docopt` takes 6 optional arguments:\n\n- `docstring` could be a module docstring (`__doc__`) or some other string\n that contains a **help message** that will be parsed to create the\n option parser. The simple rules of how to write such a help message\n are given in next sections. Here is a quick example of such a\n string:\n\n``` {.sourceCode .python}\n\"\"\"Usage: my_program.py [-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 If it is None (not provided) - the calling scope will be interrogated for a docstring.\n\n- `argv` is an optional argument vector; by default `docopt` uses the\n argument vector passed to your program (`sys.argv[1:]`).\n Alternatively you can supply a list of strings like\n `['--verbose', '-o', 'hai.txt']`.\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 (options\n should exist in usage pattern, more on that below). If you want to\n handle `-h` or `--help` options manually (as other options), set\n `help=False`.\n- `version`, by default `None`, is an optional argument that specifies\n 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` could be any printable object, but\n most likely a string, e.g. `\"2.1.0rc1\"`.\n\n > Note, when `docopt` is set to automatically handle `-h`, `--help`\n > and `--version` options, you still need to mention them in usage\n > pattern for this to work. Also, for your users to know about them.\n\n- `options_first`, by default `False`. If set to `True` will disallow\n mixing options and positional argument. I.e. after first positional\n argument, all arguments will be interpreted as positional even if\n the look like options. This can be used for strict compatibility\n with POSIX, or if you want to dispatch your arguments to other\n programs.\n\n- `more_magic`, by default `False`. If set to `True` more advanced\n efforts will be made to correct `--long_form` arguments, ie:\n `--hlep` will be corrected to `--help`. Additionally, if not\n already defined, the variable `arguments` will be created and populated\n in the calling scope. `more_magic` is also set True if `docopt()` is\n is aliased to a name containing `magic` ie) by built-in`from docopt import magic` or\n user-defined `from docopt import docopt as magic_docopt_wrapper` for convenience.\n\nThe **return** value is a simple dictionary with options, arguments and\ncommands as keys, spelled exactly like in your help message. Long\nversions of options are given priority. Furthermore, dot notation is\nsupported, with preceeding dashes (`-`) and surrounding brackets (`<>`)\nignored. For example, if you invoke the top example as:\n\n naval_fate.py ship Guardian move 100 150 --speed=15\n\nthe return dictionary will be:\n\n``` {.sourceCode .python}\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 '': ['Guardian'], 'ship': True,\n '': '100', 'shoot': False,\n '': '150'}\n```\n\n...and properties can be accessed with `arguments.drifting` or `arguments.x`.\n\n# Help message format\n\nHelp message consists of 2 parts:\n\n- Usage pattern, e.g.:\n\n Usage: my_program.py [-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\n## Usage pattern format\n\n**Usage pattern** is a substring of `doc` that starts with `usage:`\n(case *insensitive*) and ends with a *visibly* empty line. Minimum\nexample:\n\n``` {.sourceCode .python}\n\"\"\"Usage: my_program.py\n\n\"\"\"\n```\n\nThe first word after `usage:` is interpreted as your program's name. You\ncan specify your program's name several times to signify several\nexclusive patterns:\n\n``` {.sourceCode .python}\n\"\"\"Usage: my_program.py FILE\n my_program.py COUNT FILE\n\n\"\"\"\n```\n\nEach pattern can consist of the following elements:\n\n- **<arguments>**, **ARGUMENTS**. Arguments are specified as\n either upper-case words, e.g. `my_program.py CONTENT-PATH` or words\n surrounded by angular brackets: `my_program.py `.\n- **--options**. Options are words started with dash (`-`), e.g.\n `--output`, `-o`. You can \"stack\" several of one-letter options,\n e.g. `-oiv` which will be the same as `-o -i -v`. The options can\n have arguments, e.g. `--input=FILE` or `-i FILE` or even `-iFILE`.\n However it is important that you specify option descriptions if you\n want your option to have an argument, a default value, or specify\n synonymous short/long versions of the option (see next section on\n option descriptions).\n- **commands** are words that do *not* follow the described above\n conventions of `--options` or `` or `ARGUMENTS`, plus two\n special commands: dash \"`-`\" and double dash \"`--`\" (see below).\n\nUse the following constructs to specify patterns:\n\n- **\\[ \\]** (brackets) **optional** elements. e.g.:\n `my_program.py [-hvqo FILE]`\n- **( )** (parens) **required** elements. All elements that are *not*\n put in **\\[ \\]** are also required, e.g.:\n `my_program.py --path= ...` is the same as\n `my_program.py (--path= ...)`. (Note, \"required options\"\n might be not 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.py (--clockwise | --counter-clockwise) TIME`. Group them\n using **\\[ \\]** if none of the mutually-exclusive elements are\n required: `my_program.py [--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.py FILE ...` means one or more\n `FILE`-s are accepted. If you want to accept zero or more elements,\n use brackets, e.g.: `my_program.py [FILE ...]`. Ellipsis works as a\n 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 \"`[-]`\" to\n 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.py [-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 -vv`.\nSame 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.py --path=...\n\nI.e. invoked with\n`my_program.py file1 file2 --path=./here --path=./there` the returned\ndict will contain `args[''] == ['file1', 'file2']` and\n`args['--path'] == ['./here', './there']`.\n\n## Option descriptions format\n\n**Option descriptions** consist of a list of options that you put below\nyour 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 <angular-brackets> or UPPER-CASE convention for\n options' arguments. You can use comma if you want to separate\n options. In the example below, both lines are valid, however you are\n recommended to stick to a single style.:\n\n -o FILE --output=FILE # without comma, with \"=\" sign\n -i , --input # with comma, without \"=\" sign\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\n `[default: ]`:\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 splited into a list on whitespace:\n\n Usage: my_program.py [--repeatable= --repeatable=]\n [--another-repeatable=]...\n [--not-repeatable=]\n\n # will be ['./here', './there']\n --repeatable= [default: ./here ./there]\n\n # will be ['./here']\n --another-repeatable= [default: ./here]\n\n # will be './here ./there', because it is not repeatable\n --not-repeatable= [default: ./here ./there]\n\n## Examples\n\nWe have an extensive list of\n[examples](https://github.com/bazaar-projects/docopt-ng/tree/master/examples)\nwhich cover every aspect of functionality of **docopt-ng**. Try them\nout, read the source if in doubt.\n\n# Development\n\nWe would *love* to hear what you think about **docopt-ng** on our\n[issues page](https://github.com/bazaar-projects/docopt-ng/issues)\n\nMake pull requests, report bugs, suggest ideas and discuss\n**docopt-ng**.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bazaar-projects/docopt-ng", "keywords": "option arguments parsing optparse argparse getopt docopt docopt-ng", "license": "MIT", "maintainer": "itdaniher", "maintainer_email": "itdaniher@gmail.com", "name": "docopt-ng", "package_url": "https://pypi.org/project/docopt-ng/", "platform": "", "project_url": "https://pypi.org/project/docopt-ng/", "project_urls": { "Homepage": "https://github.com/bazaar-projects/docopt-ng" }, "release_url": "https://pypi.org/project/docopt-ng/0.7.2/", "requires_dist": null, "requires_python": "", "summary": "More-magic command line arguments parser. Now with more maintenance!", "version": "0.7.2" }, "last_serial": 4988562, "releases": { "0.6.3": [ { "comment_text": "", "digests": { "md5": "ee28f3355fe5527aa5fcda90337d16e3", "sha256": "82ccfcc1ded48d97c74a5a0ce3c741dd85227c1ccb83383882a0ac7b954f9901" }, "downloads": -1, "filename": "docopt_ng-0.6.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ee28f3355fe5527aa5fcda90337d16e3", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 21625, "upload_time": "2019-03-21T05:46:18", "url": "https://files.pythonhosted.org/packages/74/1e/cc308e33d0765714df1e407337beaa928f7f5eca1efeb6f5d291a61e5d65/docopt_ng-0.6.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7b4bed35045a3a259162debefde22cb5", "sha256": "12daf174d6e98c0009d58a847915a122ec6024a7c2d26e29a6b7b36fbab4402d" }, "downloads": -1, "filename": "docopt_ng-0.6.3-py3.6.egg", "has_sig": false, "md5_digest": "7b4bed35045a3a259162debefde22cb5", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 15874, "upload_time": "2019-03-21T05:46:20", "url": "https://files.pythonhosted.org/packages/24/2e/d6d15221972766013ac4fc5a61dd9ef20b752a73cea669b60e106a2bc3bd/docopt_ng-0.6.3-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "6391b4da0abfb9590f8fd6ddd9b0a4bd", "sha256": "31b6507eb0b8e3dc5d620d3041a2dacffce00ba96e87b688378f553b8697d6bb" }, "downloads": -1, "filename": "docopt-ng-0.6.3.tar.gz", "has_sig": false, "md5_digest": "6391b4da0abfb9590f8fd6ddd9b0a4bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23438, "upload_time": "2019-03-21T05:46:21", "url": "https://files.pythonhosted.org/packages/0f/89/dd280934c3facb14219e2e9464155daea1cc280010cd0f7f080abb6bdf92/docopt-ng-0.6.3.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "6dbf0c78a87bf854a3613d7b59a4c866", "sha256": "6930dc392a2a36660665c7d41162cb78284a3bd8f92173b55c5748672fba56fc" }, "downloads": -1, "filename": "docopt_ng-0.7.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6dbf0c78a87bf854a3613d7b59a4c866", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22528, "upload_time": "2019-03-23T22:03:02", "url": "https://files.pythonhosted.org/packages/cf/06/28889fd0b8ea8b4ab7557f5f4de939036b825f880f5b61a98c30a9899e38/docopt_ng-0.7.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d4c7d0cec9eaaca16a48d9e1b6d92588", "sha256": "ce402a038345eaeeab7fc6d1baa5d73674e1b13f4c8baa477a2c5d2940b923d4" }, "downloads": -1, "filename": "docopt-ng-0.7.0.tar.gz", "has_sig": false, "md5_digest": "d4c7d0cec9eaaca16a48d9e1b6d92588", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24465, "upload_time": "2019-03-23T22:03:03", "url": "https://files.pythonhosted.org/packages/14/a7/2f4c5db3cf2bc9a9701eb9703ca9a994c4404eaa9b42edc57c8af2064d59/docopt-ng-0.7.0.tar.gz" } ], "0.7.1": [ { "comment_text": "", "digests": { "md5": "80f3734c23d21a5821dc016867c20ae9", "sha256": "6e1eeee578656c2853821d2fd3ca09e230dbe941dda34bf0987b0806c8f49a2a" }, "downloads": -1, "filename": "docopt_ng-0.7.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "80f3734c23d21a5821dc016867c20ae9", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22310, "upload_time": "2019-03-24T16:06:58", "url": "https://files.pythonhosted.org/packages/7a/f5/b277d8cf7b80c6032b9194c3ed5af5bebc5fb97f74fd4f6bd1d8541b4586/docopt_ng-0.7.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "100bf6ccfbf6d72fda6d903027d204b4", "sha256": "bb3a3982db054c3e275e69cd8917e9cecfab4ba8fceb0b3802a7f112dc5e23f9" }, "downloads": -1, "filename": "docopt-ng-0.7.1.tar.gz", "has_sig": false, "md5_digest": "100bf6ccfbf6d72fda6d903027d204b4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24391, "upload_time": "2019-03-24T16:06:59", "url": "https://files.pythonhosted.org/packages/75/b1/149bd67b315c97ceea106fbde823d5f971c1cc51b4d7da674bb80d2a4402/docopt-ng-0.7.1.tar.gz" } ], "0.7.2": [ { "comment_text": "", "digests": { "md5": "e62313a5a6e8d2bd52bd9a5c343168a4", "sha256": "e98145cc02220ac5b1a8ee1c40ca9cc0cbd8e480a1b4928872bde686dc48660b" }, "downloads": -1, "filename": "docopt_ng-0.7.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e62313a5a6e8d2bd52bd9a5c343168a4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22799, "upload_time": "2019-03-26T17:03:46", "url": "https://files.pythonhosted.org/packages/69/ac/d8ef8c9d807f70de7166e4e9bb10c402e3f426460ec008d4bea8866236a1/docopt_ng-0.7.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dfd62c25ffc367ae43546266a0a3feea", "sha256": "86ceea032f0cfa59e60776eb0cf38ac73653581022872320f47dc874678d7244" }, "downloads": -1, "filename": "docopt-ng-0.7.2.tar.gz", "has_sig": false, "md5_digest": "dfd62c25ffc367ae43546266a0a3feea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24678, "upload_time": "2019-03-26T17:03:48", "url": "https://files.pythonhosted.org/packages/0c/d9/32b15c68ee7ef619986bf0e9f6f130a3c3c6e40631727f803eb0caef93c7/docopt-ng-0.7.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e62313a5a6e8d2bd52bd9a5c343168a4", "sha256": "e98145cc02220ac5b1a8ee1c40ca9cc0cbd8e480a1b4928872bde686dc48660b" }, "downloads": -1, "filename": "docopt_ng-0.7.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e62313a5a6e8d2bd52bd9a5c343168a4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 22799, "upload_time": "2019-03-26T17:03:46", "url": "https://files.pythonhosted.org/packages/69/ac/d8ef8c9d807f70de7166e4e9bb10c402e3f426460ec008d4bea8866236a1/docopt_ng-0.7.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dfd62c25ffc367ae43546266a0a3feea", "sha256": "86ceea032f0cfa59e60776eb0cf38ac73653581022872320f47dc874678d7244" }, "downloads": -1, "filename": "docopt-ng-0.7.2.tar.gz", "has_sig": false, "md5_digest": "dfd62c25ffc367ae43546266a0a3feea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24678, "upload_time": "2019-03-26T17:03:48", "url": "https://files.pythonhosted.org/packages/0c/d9/32b15c68ee7ef619986bf0e9f6f130a3c3c6e40631727f803eb0caef93c7/docopt-ng-0.7.2.tar.gz" } ] }