Comparing version 1.0.10 to 2.0.0
193
CHANGELOG.md
@@ -1,34 +0,44 @@ | ||
1.0.10 / 2018-02-15 | ||
------------------ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## [2.0.0] - 2020-08-14 | ||
### Changed | ||
- Full rewrite. Now port from python 3.9.0 & more precise following. | ||
See [doc](./doc) for difference and migration info. | ||
- node.js 10+ required | ||
- Removed most of local docs in favour of original ones. | ||
## [1.0.10] - 2018-02-15 | ||
### Fixed | ||
- Use .concat instead of + for arrays, #122. | ||
1.0.9 / 2016-09-29 | ||
------------------ | ||
## [1.0.9] - 2016-09-29 | ||
### Changed | ||
- Rerelease after 1.0.8 - deps cleanup. | ||
1.0.8 / 2016-09-29 | ||
------------------ | ||
## [1.0.8] - 2016-09-29 | ||
### Changed | ||
- Maintenance (deps bump, fix node 6.5+ tests, coverage report). | ||
1.0.7 / 2016-03-17 | ||
------------------ | ||
## [1.0.7] - 2016-03-17 | ||
### Changed | ||
- Teach `addArgument` to accept string arg names. #97, @tomxtobin. | ||
1.0.6 / 2016-02-06 | ||
------------------ | ||
## [1.0.6] - 2016-02-06 | ||
### Changed | ||
- Maintenance: moved to eslint & updated CS. | ||
1.0.5 / 2016-02-05 | ||
------------------ | ||
## [1.0.5] - 2016-02-05 | ||
### Changed | ||
- Removed lodash dependency to significantly reduce install size. | ||
@@ -38,29 +48,24 @@ Thanks to @mourner. | ||
1.0.4 / 2016-01-17 | ||
------------------ | ||
## [1.0.4] - 2016-01-17 | ||
### Changed | ||
- Maintenance: lodash update to 4.0.0. | ||
1.0.3 / 2015-10-27 | ||
------------------ | ||
## [1.0.3] - 2015-10-27 | ||
### Fixed | ||
- Fix parse `=` in args: `--examplepath="C:\myfolder\env=x64"`. #84, @CatWithApple. | ||
1.0.2 / 2015-03-22 | ||
------------------ | ||
## [1.0.2] - 2015-03-22 | ||
### Changed | ||
- Relaxed lodash version dependency. | ||
1.0.1 / 2015-02-20 | ||
------------------ | ||
## [1.0.1] - 2015-02-20 | ||
### Changed | ||
- Changed dependencies to be compatible with ancient nodejs. | ||
1.0.0 / 2015-02-19 | ||
------------------ | ||
## [1.0.0] - 2015-02-19 | ||
### Changed | ||
- Maintenance release. | ||
@@ -72,36 +77,29 @@ - Replaced `underscore` with `lodash`. | ||
0.1.16 / 2013-12-01 | ||
------------------- | ||
## [0.1.16] - 2013-12-01 | ||
### Changed | ||
- Maintenance release. Updated dependencies and docs. | ||
0.1.15 / 2013-05-13 | ||
------------------- | ||
## [0.1.15] - 2013-05-13 | ||
### Fixed | ||
- Fixed #55, @trebor89 | ||
0.1.14 / 2013-05-12 | ||
------------------- | ||
## [0.1.14] - 2013-05-12 | ||
### Fixed | ||
- Fixed #62, @maxtaco | ||
0.1.13 / 2013-04-08 | ||
------------------- | ||
## [0.1.13] - 2013-04-08 | ||
### Changed | ||
- Added `.npmignore` to reduce package size | ||
0.1.12 / 2013-02-10 | ||
------------------- | ||
## [0.1.12] - 2013-02-10 | ||
### Fixed | ||
- Fixed conflictHandler (#46), @hpaulj | ||
0.1.11 / 2013-02-07 | ||
------------------- | ||
- Multiple bugfixes, @hpaulj | ||
## [0.1.11] - 2013-02-07 | ||
### Added | ||
- Added 70+ tests (ported from python), @hpaulj | ||
@@ -111,23 +109,25 @@ - Added conflictHandler, @applepicke | ||
### Fixed | ||
- Multiple bugfixes, @hpaulj | ||
0.1.10 / 2012-12-30 | ||
------------------- | ||
## [0.1.10] - 2012-12-30 | ||
### Added | ||
- Added [mutual exclusion](http://docs.python.org/dev/library/argparse.html#mutual-exclusion) | ||
support, thanks to @hpaulj | ||
### Fixed | ||
- Fixed options check for `storeConst` & `appendConst` actions, thanks to @hpaulj | ||
0.1.9 / 2012-12-27 | ||
------------------ | ||
## [0.1.9] - 2012-12-27 | ||
### Fixed | ||
- Fixed option dest interferens with other options (issue #23), thanks to @hpaulj | ||
- Fixed default value behavior with `*` positionals, thanks to @hpaulj | ||
- Improve `getDefault()` behavior, thanks to @hpaulj | ||
- Imrove negative argument parsing, thanks to @hpaulj | ||
- Improve negative argument parsing, thanks to @hpaulj | ||
0.1.8 / 2012-12-01 | ||
------------------ | ||
## [0.1.8] - 2012-12-01 | ||
### Fixed | ||
- Fixed parser parents (issue #19), thanks to @hpaulj | ||
@@ -137,5 +137,4 @@ - Fixed negative argument parse (issue #20), thanks to @hpaulj | ||
0.1.7 / 2012-10-14 | ||
------------------ | ||
## [0.1.7] - 2012-10-14 | ||
### Fixed | ||
- Fixed 'choices' argument parse (issue #16) | ||
@@ -145,17 +144,14 @@ - Fixed stderr output (issue #15) | ||
0.1.6 / 2012-09-09 | ||
------------------ | ||
## [0.1.6] - 2012-09-09 | ||
### Fixed | ||
- Fixed check for conflict of options (thanks to @tomxtobin) | ||
0.1.5 / 2012-09-03 | ||
------------------ | ||
## [0.1.5] - 2012-09-03 | ||
### Fixed | ||
- Fix parser #setDefaults method (thanks to @tomxtobin) | ||
0.1.4 / 2012-07-30 | ||
------------------ | ||
## [0.1.4] - 2012-07-30 | ||
### Fixed | ||
- Fixed pseudo-argument support (thanks to @CGamesPlay) | ||
@@ -165,12 +161,9 @@ - Fixed addHelp default (should be true), if not set (thanks to @benblank) | ||
0.1.3 / 2012-06-27 | ||
------------------ | ||
## [0.1.3] - 2012-06-27 | ||
### Fixed | ||
- Fixed formatter api name: Formatter -> HelpFormatter | ||
0.1.2 / 2012-05-29 | ||
------------------ | ||
- Added basic tests | ||
## [0.1.2] - 2012-05-29 | ||
### Fixed | ||
- Removed excess whitespace in help | ||
@@ -180,6 +173,8 @@ - Fixed error reporting, when parcer with subcommands | ||
### Added | ||
- Added basic tests | ||
0.1.1 / 2012-05-23 | ||
------------------ | ||
## [0.1.1] - 2012-05-23 | ||
### Fixed | ||
- Fixed line wrapping in help formatter | ||
@@ -189,5 +184,35 @@ - Added better error reporting on invalid arguments | ||
0.1.0 / 2012-05-16 | ||
------------------ | ||
## [0.1.0] - 2012-05-16 | ||
### Added | ||
- First release. | ||
- First release. | ||
[2.0.0]: https://github.com/nodeca/argparse/compare/1.0.10...2.0.0 | ||
[1.0.10]: https://github.com/nodeca/argparse/compare/1.0.9...1.0.10 | ||
[1.0.9]: https://github.com/nodeca/argparse/compare/1.0.8...1.0.9 | ||
[1.0.8]: https://github.com/nodeca/argparse/compare/1.0.7...1.0.8 | ||
[1.0.7]: https://github.com/nodeca/argparse/compare/1.0.6...1.0.7 | ||
[1.0.6]: https://github.com/nodeca/argparse/compare/1.0.5...1.0.6 | ||
[1.0.5]: https://github.com/nodeca/argparse/compare/1.0.4...1.0.5 | ||
[1.0.4]: https://github.com/nodeca/argparse/compare/1.0.3...1.0.4 | ||
[1.0.3]: https://github.com/nodeca/argparse/compare/1.0.2...1.0.3 | ||
[1.0.2]: https://github.com/nodeca/argparse/compare/1.0.1...1.0.2 | ||
[1.0.1]: https://github.com/nodeca/argparse/compare/1.0.0...1.0.1 | ||
[1.0.0]: https://github.com/nodeca/argparse/compare/0.1.16...1.0.0 | ||
[0.1.16]: https://github.com/nodeca/argparse/compare/0.1.15...0.1.16 | ||
[0.1.15]: https://github.com/nodeca/argparse/compare/0.1.14...0.1.15 | ||
[0.1.14]: https://github.com/nodeca/argparse/compare/0.1.13...0.1.14 | ||
[0.1.13]: https://github.com/nodeca/argparse/compare/0.1.12...0.1.13 | ||
[0.1.12]: https://github.com/nodeca/argparse/compare/0.1.11...0.1.12 | ||
[0.1.11]: https://github.com/nodeca/argparse/compare/0.1.10...0.1.11 | ||
[0.1.10]: https://github.com/nodeca/argparse/compare/0.1.9...0.1.10 | ||
[0.1.9]: https://github.com/nodeca/argparse/compare/0.1.8...0.1.9 | ||
[0.1.8]: https://github.com/nodeca/argparse/compare/0.1.7...0.1.8 | ||
[0.1.7]: https://github.com/nodeca/argparse/compare/0.1.6...0.1.7 | ||
[0.1.6]: https://github.com/nodeca/argparse/compare/0.1.5...0.1.6 | ||
[0.1.5]: https://github.com/nodeca/argparse/compare/0.1.4...0.1.5 | ||
[0.1.4]: https://github.com/nodeca/argparse/compare/0.1.3...0.1.4 | ||
[0.1.3]: https://github.com/nodeca/argparse/compare/0.1.2...0.1.3 | ||
[0.1.2]: https://github.com/nodeca/argparse/compare/0.1.1...0.1.2 | ||
[0.1.1]: https://github.com/nodeca/argparse/compare/0.1.0...0.1.1 | ||
[0.1.0]: https://github.com/nodeca/argparse/releases/tag/0.1.0 |
{ | ||
"name": "argparse", | ||
"description": "Very powerful CLI arguments parser. Native port of argparse - python's options parsing library", | ||
"version": "1.0.10", | ||
"description": "CLI arguments parser. Native port of python's argparse.", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -12,24 +12,21 @@ "cli", | ||
], | ||
"contributors": [ | ||
"Eugene Shkuropat", | ||
"Paul Jacobson" | ||
], | ||
"main": "argparse.js", | ||
"files": [ | ||
"index.js", | ||
"argparse.js", | ||
"lib/" | ||
], | ||
"license": "MIT", | ||
"license": "Python-2.0", | ||
"repository": "nodeca/argparse", | ||
"scripts": { | ||
"test": "make test" | ||
"lint": "eslint .", | ||
"test": "npm run lint && nyc mocha", | ||
"coverage": "npm run test && nyc report --reporter html" | ||
}, | ||
"dependencies": { | ||
"sprintf-js": "~1.0.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^2.13.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.1.0", | ||
"ndoc": "^5.0.1" | ||
"@babel/eslint-parser": "^7.11.0", | ||
"@babel/plugin-syntax-class-properties": "^7.10.4", | ||
"eslint": "^7.5.0", | ||
"mocha": "^8.0.1", | ||
"nyc": "^15.1.0" | ||
} | ||
} |
247
README.md
@@ -7,21 +7,19 @@ argparse | ||
CLI arguments parser for node.js. Javascript port of python's | ||
[argparse](http://docs.python.org/dev/library/argparse.html) module | ||
(original version 3.2). That's a full port, except some very rare options, | ||
recorded in issue tracker. | ||
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)). | ||
**NB. Difference with original.** | ||
**Difference with original.** | ||
- Method names changed to camelCase. See [generated docs](http://nodeca.github.com/argparse/). | ||
- Use `defaultValue` instead of `default`. | ||
- Use `argparse.Const.REMAINDER` instead of `argparse.REMAINDER`, and | ||
similarly for constant values `OPTIONAL`, `ZERO_OR_MORE`, and `ONE_OR_MORE` | ||
(aliases for `nargs` values `'?'`, `'*'`, `'+'`, respectively), and | ||
`SUPPRESS`. | ||
- JS has no keyword arguments support. | ||
- Pass options instead: `new ArgumentParser({ description: 'example', add_help: true })`. | ||
- JS has no python's types `int`, `float`, ... | ||
- Use string-typed names: `.add_argument('-b', { type: 'int', help: 'help' })`. | ||
- `%r` format specifier uses `require('util').inspect()`. | ||
More details in [doc](./doc). | ||
Example | ||
======= | ||
------- | ||
test.js file: | ||
`test.js` file: | ||
@@ -32,28 +30,15 @@ ```javascript | ||
var ArgumentParser = require('../lib/argparse').ArgumentParser; | ||
var parser = new ArgumentParser({ | ||
version: '0.0.1', | ||
addHelp:true, | ||
const { ArgumentParser } = require('argparse'); | ||
const { version } = require('./package.json'); | ||
const parser = new ArgumentParser({ | ||
description: 'Argparse example' | ||
}); | ||
parser.addArgument( | ||
[ '-f', '--foo' ], | ||
{ | ||
help: 'foo bar' | ||
} | ||
); | ||
parser.addArgument( | ||
[ '-b', '--bar' ], | ||
{ | ||
help: 'bar foo' | ||
} | ||
); | ||
parser.addArgument( | ||
'--baz', | ||
{ | ||
help: 'baz bar' | ||
} | ||
); | ||
var args = parser.parseArgs(); | ||
console.dir(args); | ||
parser.add_argument('-v', '--version', { action: 'version', version }); | ||
parser.add_argument('-f', '--foo', { help: 'foo bar' }); | ||
parser.add_argument('-b', '--bar', { help: 'bar foo' }); | ||
parser.add_argument('--baz', { help: 'baz bar' }); | ||
console.dir(parser.parse_args()); | ||
``` | ||
@@ -65,9 +50,9 @@ | ||
$ ./test.js -h | ||
usage: example.js [-h] [-v] [-f FOO] [-b BAR] [--baz BAZ] | ||
usage: test.js [-h] [-v] [-f FOO] [-b BAR] [--baz BAZ] | ||
Argparse example | ||
Optional arguments: | ||
-h, --help Show this help message and exit. | ||
-v, --version Show program's version number and exit. | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-v, --version show program's version number and exit | ||
-f FOO, --foo FOO foo bar | ||
@@ -85,177 +70,19 @@ -b BAR, --bar BAR bar foo | ||
More [examples](https://github.com/nodeca/argparse/tree/master/examples). | ||
API docs | ||
-------- | ||
ArgumentParser objects | ||
====================== | ||
Since this is a port with minimal divergence, there's no separate documentation. | ||
Use original one instead, with notes about difference. | ||
``` | ||
new ArgumentParser({parameters hash}); | ||
``` | ||
1. [Original doc](https://docs.python.org/3.9/library/argparse.html). | ||
2. [Original tutorial](https://docs.python.org/3.9/howto/argparse.html). | ||
3. [Difference with python](./doc). | ||
Creates a new ArgumentParser object. | ||
**Supported params:** | ||
argparse for enterprise | ||
----------------------- | ||
- ```description``` - Text to display before the argument help. | ||
- ```epilog``` - Text to display after the argument help. | ||
- ```addHelp``` - Add a -h/–help option to the parser. (default: true) | ||
- ```argumentDefault``` - Set the global default value for arguments. (default: null) | ||
- ```parents``` - A list of ArgumentParser objects whose arguments should also be included. | ||
- ```prefixChars``` - The set of characters that prefix optional arguments. (default: ‘-‘) | ||
- ```formatterClass``` - A class for customizing the help output. | ||
- ```prog``` - The name of the program (default: `path.basename(process.argv[1])`) | ||
- ```usage``` - The string describing the program usage (default: generated) | ||
- ```conflictHandler``` - Usually unnecessary, defines strategy for resolving conflicting optionals. | ||
Available as part of the Tidelift Subscription | ||
**Not supported yet** | ||
- ```fromfilePrefixChars``` - The set of characters that prefix files from which additional arguments should be read. | ||
Details in [original ArgumentParser guide](http://docs.python.org/dev/library/argparse.html#argumentparser-objects) | ||
addArgument() method | ||
==================== | ||
``` | ||
ArgumentParser.addArgument(name or flag or [name] or [flags...], {options}) | ||
``` | ||
Defines how a single command-line argument should be parsed. | ||
- ```name or flag or [name] or [flags...]``` - Either a positional name | ||
(e.g., `'foo'`), a single option (e.g., `'-f'` or `'--foo'`), an array | ||
of a single positional name (e.g., `['foo']`), or an array of options | ||
(e.g., `['-f', '--foo']`). | ||
Options: | ||
- ```action``` - The basic type of action to be taken when this argument is encountered at the command line. | ||
- ```nargs```- The number of command-line arguments that should be consumed. | ||
- ```constant``` - A constant value required by some action and nargs selections. | ||
- ```defaultValue``` - The value produced if the argument is absent from the command line. | ||
- ```type``` - The type to which the command-line argument should be converted. | ||
- ```choices``` - A container of the allowable values for the argument. | ||
- ```required``` - Whether or not the command-line option may be omitted (optionals only). | ||
- ```help``` - A brief description of what the argument does. | ||
- ```metavar``` - A name for the argument in usage messages. | ||
- ```dest``` - The name of the attribute to be added to the object returned by parseArgs(). | ||
Details in [original add_argument guide](http://docs.python.org/dev/library/argparse.html#the-add-argument-method) | ||
Action (some details) | ||
================ | ||
ArgumentParser objects associate command-line arguments with actions. | ||
These actions can do just about anything with the command-line arguments associated | ||
with them, though most actions simply add an attribute to the object returned by | ||
parseArgs(). The action keyword argument specifies how the command-line arguments | ||
should be handled. The supported actions are: | ||
- ```store``` - Just stores the argument’s value. This is the default action. | ||
- ```storeConst``` - Stores value, specified by the const keyword argument. | ||
(Note that the const keyword argument defaults to the rather unhelpful None.) | ||
The 'storeConst' action is most commonly used with optional arguments, that | ||
specify some sort of flag. | ||
- ```storeTrue``` and ```storeFalse``` - Stores values True and False | ||
respectively. These are special cases of 'storeConst'. | ||
- ```append``` - Stores a list, and appends each argument value to the list. | ||
This is useful to allow an option to be specified multiple times. | ||
- ```appendConst``` - Stores a list, and appends value, specified by the | ||
const keyword argument to the list. (Note, that the const keyword argument defaults | ||
is None.) The 'appendConst' action is typically used when multiple arguments need | ||
to store constants to the same list. | ||
- ```count``` - Counts the number of times a keyword argument occurs. For example, | ||
used for increasing verbosity levels. | ||
- ```help``` - Prints a complete help message for all the options in the current | ||
parser and then exits. By default a help action is automatically added to the parser. | ||
See ArgumentParser for details of how the output is created. | ||
- ```version``` - Prints version information and exit. Expects a `version=` | ||
keyword argument in the addArgument() call. | ||
Details in [original action guide](http://docs.python.org/dev/library/argparse.html#action) | ||
Sub-commands | ||
============ | ||
ArgumentParser.addSubparsers() | ||
Many programs split their functionality into a number of sub-commands, for | ||
example, the svn program can invoke sub-commands like `svn checkout`, `svn update`, | ||
and `svn commit`. Splitting up functionality this way can be a particularly good | ||
idea when a program performs several different functions which require different | ||
kinds of command-line arguments. `ArgumentParser` supports creation of such | ||
sub-commands with `addSubparsers()` method. The `addSubparsers()` method is | ||
normally called with no arguments and returns an special action object. | ||
This object has a single method `addParser()`, which takes a command name and | ||
any `ArgumentParser` constructor arguments, and returns an `ArgumentParser` object | ||
that can be modified as usual. | ||
Example: | ||
sub_commands.js | ||
```javascript | ||
#!/usr/bin/env node | ||
'use strict'; | ||
var ArgumentParser = require('../lib/argparse').ArgumentParser; | ||
var parser = new ArgumentParser({ | ||
version: '0.0.1', | ||
addHelp:true, | ||
description: 'Argparse examples: sub-commands', | ||
}); | ||
var subparsers = parser.addSubparsers({ | ||
title:'subcommands', | ||
dest:"subcommand_name" | ||
}); | ||
var bar = subparsers.addParser('c1', {addHelp:true}); | ||
bar.addArgument( | ||
[ '-f', '--foo' ], | ||
{ | ||
action: 'store', | ||
help: 'foo3 bar3' | ||
} | ||
); | ||
var bar = subparsers.addParser( | ||
'c2', | ||
{aliases:['co'], addHelp:true} | ||
); | ||
bar.addArgument( | ||
[ '-b', '--bar' ], | ||
{ | ||
action: 'store', | ||
type: 'int', | ||
help: 'foo3 bar3' | ||
} | ||
); | ||
var args = parser.parseArgs(); | ||
console.dir(args); | ||
``` | ||
Details in [original sub-commands guide](http://docs.python.org/dev/library/argparse.html#sub-commands) | ||
Contributors | ||
============ | ||
- [Eugene Shkuropat](https://github.com/shkuropat) | ||
- [Paul Jacobson](https://github.com/hpaulj) | ||
[others](https://github.com/nodeca/argparse/graphs/contributors) | ||
License | ||
======= | ||
Copyright (c) 2012 [Vitaly Puzrin](https://github.com/puzrin). | ||
Released under the MIT license. See | ||
[LICENSE](https://github.com/nodeca/argparse/blob/master/LICENSE) for details. | ||
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) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171322
0
3692
5
7
1
2
85
1
- Removedsprintf-js@~1.0.2
- Removedsprintf-js@1.0.3(transitive)