Gathering detailed insights and metrics for cli-argparse
Gathering detailed insights and metrics for cli-argparse
Gathering detailed insights and metrics for cli-argparse
Gathering detailed insights and metrics for cli-argparse
npm install cli-argparse
74.4
Supply Chain
98.9
Quality
78.3
Maintenance
100
Vulnerability
100
License
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
6 Stars
162 Commits
1 Watching
2 Branches
1 Contributors
Updated on 19 Dec 2021
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
429%
164
Compared to previous day
Last week
216.1%
531
Compared to previous week
Last month
81.6%
1,195
Compared to previous month
Last year
-29.6%
13,458
Compared to previous year
Lightweight yet feature rich argument parser.
This module does not define any options or any program requirements it simply parses arguments into an object structure that is easier for other modules to work with.
--no-color
.--option=value
, --option value
and option=value
.-xvf
.-ddd
.-xvf file.tgz
.-
as special stdin flag.--
.npm install cli-argparse
1var parse = require('./index'); 2var args = [ 3 'server', 4 'start', 5 '-xvd', 6 '--port=80', 7 '--config', 8 '-', 9 '--config=config.json', 10 '--log', 11 'server.log', 12 '--no-color' 13]; 14var result = parse(args); 15console.log(JSON.stringify(result, undefined, 2));
1{ 2 "flags": { 3 "x": true, 4 "v": true, 5 "d": true, 6 "color": false 7 }, 8 "options": { 9 "port": "80", 10 "config": [ 11 "-", 12 "config.json" 13 ], 14 "log": "server.log" 15 }, 16 "raw": [ 17 "server", 18 "start", 19 "-xvd", 20 "--port=80", 21 "--config", 22 "-", 23 "--config=config.json", 24 "--log", 25 "server.log", 26 "--no-color" 27 ], 28 "stdin": true, 29 "unparsed": [ 30 "server", 31 "start" 32 ], 33 "strict": false, 34 "vars": {} 35}
1var parse = require('cli-argparse'); 2var result = parse(); 3console.dir(result);
args
: Specific arguments to parse, default is process.argv.slice(2)
.options
: Parsing configuration options.Returns a result object.
alias
: Map of argument names to property names.flags
: Array of argument names to be treated as flags.options
: Array of argument names to be treated as options.short
: Allow short options to have values.strict
: A boolean that indicates only arguments specified as options
or flags
should be parsed.flat
: A boolean that creates a flat result structure.stop
: Array of strings or patterns to stop parsing on, the special pattern --
is always respected first.vars
: A string or regexp used to collect variables into the vars
object.camelcase
: When false
do not convert option names to camelcase; when a string or regexp split the option name on the given pattern for conversion to camelcase.The result object contains the fields:
flags
: Object containing arguments treated as flags.options
: Object containing arguments treated as options with values.raw
: Array of the raw arguments parsed.stdin
: Boolean indicating whether -
is present in the argument list.unparsed
: Array of values that were not parsed.skip
: Array of args skipped upon --
or a custom stop pattern.stop
: If a stop pattern matched this will contain the pattern that matched (string or regexp).empty
: Set to true
if a stop pattern matched on the first argument.vars
: Variables collected when the vars
option is configured.Aliases allow arguments to map to meaningful property names that will be set on the result object options
and flags
.
Aliases are mapped on the raw argument name, to map -v | --verbose
to a verbose
property use {'-v --verbose': 'verbose'}
.
Note that you should not use the negated long form (--no-highlight) when specifying these hints, always use the positive form.
Use the flags array when you need to force a long argument to be treated as a flag, for example ['--syntax-highlight']
.
Use the options array when you need to treat a short argument as accepting a value, for example ['-f']
.
A boolean
that indicates that only known arguments (those declared in the options and flags properties) are accepted, all other arguments will be placed in the unparsed array.
Creating a flat result can be useful if you are certain that there are no naming collisions, typically this can be achieved by providing hints using flags
and options
.
When this option is specified the result object will not have a flags
property, instead all flags and options will be in the options
property of the result.
Sometimes it is useful to collect arguments following a convention, for example -D
like java or maybe all arguments prefixed with @
. When the vars
option is set all arguments that match the convention are collected in to the vars
result object, see the vars test spec for examples.
To run the test suite:
npm test
To generate code coverage run:
npm run cover
Run the source tree through jshint and jscs:
npm run lint
Remove generated files:
npm run clean
To build the readme file from the partial definitions (requires mdp):
npm run readme
Everything is MIT. Read the license if you feel inclined.
Generated by mdp(1).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More