版博士V2.0程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. argparse
  2. ========
  3. [![Build Status](https://secure.travis-ci.org/nodeca/argparse.svg?branch=master)](http://travis-ci.org/nodeca/argparse)
  4. [![NPM version](https://img.shields.io/npm/v/argparse.svg)](https://www.npmjs.org/package/argparse)
  5. CLI arguments parser for node.js, with [sub-commands](https://docs.python.org/3.9/library/argparse.html#sub-commands) support. Port of python's [argparse](http://docs.python.org/dev/library/argparse.html) (version [3.9.0](https://github.com/python/cpython/blob/v3.9.0rc1/Lib/argparse.py)).
  6. **Difference with original.**
  7. - JS has no keyword arguments support.
  8. - Pass options instead: `new ArgumentParser({ description: 'example', add_help: true })`.
  9. - JS has no python's types `int`, `float`, ...
  10. - Use string-typed names: `.add_argument('-b', { type: 'int', help: 'help' })`.
  11. - `%r` format specifier uses `require('util').inspect()`.
  12. More details in [doc](./doc).
  13. Example
  14. -------
  15. `test.js` file:
  16. ```javascript
  17. #!/usr/bin/env node
  18. 'use strict';
  19. const { ArgumentParser } = require('argparse');
  20. const { version } = require('./package.json');
  21. const parser = new ArgumentParser({
  22. description: 'Argparse example'
  23. });
  24. parser.add_argument('-v', '--version', { action: 'version', version });
  25. parser.add_argument('-f', '--foo', { help: 'foo bar' });
  26. parser.add_argument('-b', '--bar', { help: 'bar foo' });
  27. parser.add_argument('--baz', { help: 'baz bar' });
  28. console.dir(parser.parse_args());
  29. ```
  30. Display help:
  31. ```
  32. $ ./test.js -h
  33. usage: test.js [-h] [-v] [-f FOO] [-b BAR] [--baz BAZ]
  34. Argparse example
  35. optional arguments:
  36. -h, --help show this help message and exit
  37. -v, --version show program's version number and exit
  38. -f FOO, --foo FOO foo bar
  39. -b BAR, --bar BAR bar foo
  40. --baz BAZ baz bar
  41. ```
  42. Parse arguments:
  43. ```
  44. $ ./test.js -f=3 --bar=4 --baz 5
  45. { foo: '3', bar: '4', baz: '5' }
  46. ```
  47. API docs
  48. --------
  49. Since this is a port with minimal divergence, there's no separate documentation.
  50. Use original one instead, with notes about difference.
  51. 1. [Original doc](https://docs.python.org/3.9/library/argparse.html).
  52. 2. [Original tutorial](https://docs.python.org/3.9/howto/argparse.html).
  53. 3. [Difference with python](./doc).
  54. argparse for enterprise
  55. -----------------------
  56. Available as part of the Tidelift Subscription
  57. The maintainers of argparse and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-argparse?utm_source=npm-argparse&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)