You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
8.4 KiB

4 years ago
  1. Metadata-Version: 2.0
  2. Name: argh
  3. Version: 0.26.2
  4. Summary: An unobtrusive argparse wrapper with natural syntax
  5. Home-page: http://github.com/neithere/argh/
  6. Author: Andrey Mikhaylenko
  7. Author-email: neithere@gmail.com
  8. License: GNU Lesser General Public License (LGPL), Version 3
  9. Keywords: cli command line argparse optparse argument option
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 4 - Beta
  12. Classifier: Environment :: Console
  13. Classifier: Intended Audience :: Developers
  14. Classifier: Intended Audience :: Information Technology
  15. Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
  16. Classifier: Programming Language :: Python
  17. Classifier: Programming Language :: Python :: 2
  18. Classifier: Programming Language :: Python :: 2.6
  19. Classifier: Programming Language :: Python :: 2.7
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3.2
  22. Classifier: Programming Language :: Python :: 3.4
  23. Classifier: Programming Language :: Python :: Implementation :: CPython
  24. Classifier: Programming Language :: Python :: Implementation :: PyPy
  25. Classifier: Topic :: Software Development :: User Interfaces
  26. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  27. Provides: argh
  28. Argh: The Natural CLI
  29. =====================
  30. .. image:: https://img.shields.io/coveralls/neithere/argh.svg
  31. :target: https://coveralls.io/r/neithere/argh
  32. .. image:: https://img.shields.io/travis/neithere/argh.svg
  33. :target: https://travis-ci.org/neithere/argh
  34. .. image:: https://img.shields.io/pypi/format/argh.svg
  35. :target: https://pypi.python.org/pypi/argh
  36. .. image:: https://img.shields.io/pypi/status/argh.svg
  37. :target: https://pypi.python.org/pypi/argh
  38. .. image:: https://img.shields.io/pypi/v/argh.svg
  39. :target: https://pypi.python.org/pypi/argh
  40. .. image:: https://img.shields.io/pypi/pyversions/argh.svg
  41. :target: https://pypi.python.org/pypi/argh
  42. .. image:: https://img.shields.io/pypi/dd/argh.svg
  43. :target: https://pypi.python.org/pypi/argh
  44. .. image:: https://readthedocs.org/projects/argh/badge/?version=stable
  45. :target: http://argh.readthedocs.org/en/stable/
  46. .. image:: https://readthedocs.org/projects/argh/badge/?version=latest
  47. :target: http://argh.readthedocs.org/en/latest/
  48. Building a command-line interface? Found yourself uttering "argh!" while
  49. struggling with the API of `argparse`? Don't like the complexity but need
  50. the power?
  51. .. epigraph::
  52. Everything should be made as simple as possible, but no simpler.
  53. -- Albert Einstein (probably)
  54. `Argh` is a smart wrapper for `argparse`. `Argparse` is a very powerful tool;
  55. `Argh` just makes it easy to use.
  56. In a nutshell
  57. -------------
  58. `Argh`-powered applications are *simple* but *flexible*:
  59. :Modular:
  60. Declaration of commands can be decoupled from assembling and dispatching;
  61. :Pythonic:
  62. Commands are declared naturally, no complex API calls in most cases;
  63. :Reusable:
  64. Commands are plain functions, can be used directly outside of CLI context;
  65. :Layered:
  66. The complexity of code raises with requirements;
  67. :Transparent:
  68. The full power of argparse is available whenever needed;
  69. :Namespaced:
  70. Nested commands are a piece of cake, no messing with subparsers (though
  71. they are of course used under the hood);
  72. :Term-Friendly:
  73. Command output is processed with respect to stream encoding;
  74. :Unobtrusive:
  75. `Argh` can dispatch a subset of pure-`argparse` code, and pure-`argparse`
  76. code can update and dispatch a parser assembled with `Argh`;
  77. :DRY:
  78. The amount of boilerplate code is minimal; among other things, `Argh` will:
  79. * infer command name from function name;
  80. * infer arguments from function signature;
  81. * infer argument type from the default value;
  82. * infer argument action from the default value (for booleans);
  83. * add an alias root command ``help`` for the ``--help`` argument.
  84. :NIH free:
  85. `Argh` supports *completion*, *progress bars* and everything else by being
  86. friendly to excellent 3rd-party libraries. No need to reinvent the wheel.
  87. Sounds good? Check the tutorial!
  88. Relation to argparse
  89. --------------------
  90. `Argh` is fully compatible with `argparse`. You can mix `Argh`-agnostic and
  91. `Argh`-aware code. Just keep in mind that the dispatcher does some extra work
  92. that a custom dispatcher may not do.
  93. Installation
  94. ------------
  95. Using pip::
  96. $ pip install argh
  97. Arch Linux (AUR)::
  98. $ yaourt python-argh
  99. Examples
  100. --------
  101. A very simple application with one command:
  102. .. code-block:: python
  103. import argh
  104. def main():
  105. return 'Hello world'
  106. argh.dispatch_command(main)
  107. Run it:
  108. .. code-block:: bash
  109. $ ./app.py
  110. Hello world
  111. A potentially modular application with multiple commands:
  112. .. code-block:: python
  113. import argh
  114. # declaring:
  115. def echo(text):
  116. "Returns given word as is."
  117. return text
  118. def greet(name, greeting='Hello'):
  119. "Greets the user with given name. The greeting is customizable."
  120. return greeting + ', ' + name
  121. # assembling:
  122. parser = argh.ArghParser()
  123. parser.add_commands([echo, greet])
  124. # dispatching:
  125. if __name__ == '__main__':
  126. parser.dispatch()
  127. Of course it works:
  128. .. code-block:: bash
  129. $ ./app.py greet Andy
  130. Hello, Andy
  131. $ ./app.py greet Andy -g Arrrgh
  132. Arrrgh, Andy
  133. Here's the auto-generated help for this application (note how the docstrings
  134. are reused)::
  135. $ ./app.py help
  136. usage: app.py {echo,greet} ...
  137. positional arguments:
  138. echo Returns given word as is.
  139. greet Greets the user with given name. The greeting is customizable.
  140. ...and for a specific command (an ordinary function signature is converted
  141. to CLI arguments)::
  142. $ ./app.py help greet
  143. usage: app.py greet [-g GREETING] name
  144. Greets the user with given name. The greeting is customizable.
  145. positional arguments:
  146. name
  147. optional arguments:
  148. -g GREETING, --greeting GREETING 'Hello'
  149. (The help messages have been simplified a bit for brevity.)
  150. `Argh` easily maps plain Python functions to CLI. Sometimes this is not
  151. enough; in these cases the powerful API of `argparse` is also available:
  152. .. code-block:: python
  153. @arg('text', default='hello world', nargs='+', help='The message')
  154. def echo(text):
  155. print text
  156. The approaches can be safely combined even up to this level:
  157. .. code-block:: python
  158. # adding help to `foo` which is in the function signature:
  159. @arg('foo', help='blah')
  160. # these are not in the signature so they go to **kwargs:
  161. @arg('baz')
  162. @arg('-q', '--quux')
  163. # the function itself:
  164. def cmd(foo, bar=1, *args, **kwargs):
  165. yield foo
  166. yield bar
  167. yield ', '.join(args)
  168. yield kwargs['baz']
  169. yield kwargs['quux']
  170. Links
  171. -----
  172. * `Project home page`_ (GitHub)
  173. * `Documentation`_ (Read the Docs)
  174. * `Package distribution`_ (PyPI)
  175. * Questions, requests, bug reports, etc.:
  176. * `Issue tracker`_ (GitHub)
  177. * `Mailing list`_ (subscribe to get important announcements)
  178. * Direct e-mail (neithere at gmail com)
  179. .. _project home page: http://github.com/neithere/argh/
  180. .. _documentation: http://argh.readthedocs.org
  181. .. _package distribution: http://pypi.python.org/pypi/argh
  182. .. _issue tracker: http://github.com/neithere/argh/issues/
  183. .. _mailing list: http://groups.google.com/group/argh-users
  184. Author
  185. ------
  186. Developed by Andrey Mikhaylenko since 2010.
  187. See file `AUTHORS` for a complete list of contributors to this library.
  188. Support
  189. -------
  190. The fastest way to improve this project is to submit tested and documented
  191. patches or detailed bug reports.
  192. Otherwise you can "flattr" me: |FlattrLink|_
  193. .. _FlattrLink: https://flattr.com/submit/auto?user_id=neithere&url=http%3A%2F%2Fpypi.python.org%2Fpypi%2Fargh
  194. .. |FlattrLink| image:: https://api.flattr.com/button/flattr-badge-large.png
  195. :alt: Flattr the Argh project
  196. Licensing
  197. ---------
  198. Argh is free software: you can redistribute it and/or modify
  199. it under the terms of the GNU Lesser General Public License as published
  200. by the Free Software Foundation, either version 3 of the License, or
  201. (at your option) any later version.
  202. Argh is distributed in the hope that it will be useful,
  203. but WITHOUT ANY WARRANTY; without even the implied warranty of
  204. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  205. GNU Lesser General Public License for more details.
  206. You should have received a copy of the GNU Lesser General Public License
  207. along with Argh. If not, see <http://gnu.org/licenses/>.