Constructs an instance of ArgsParser with the provided argument configurations.
Configuration options for the parser.
An array of argument configurations.
Adds an action configuration to the parser.
The action configuration.
The updated parser.
Adds a new argument configuration to the parser.
The argument configuration.
The instance of ArgsParser for chaining.
Adds a help action to the parser.
Optional
name: stringThe name of the help action.
Optional
alias: stringThe alias of the help action.
The updated parser.
Adds a version action to the parser.
Optional
name: stringThe name of the version action.
Optional
alias: stringThe alias of the version action.
The updated parser.
Parses the given argument string and returns a collection of parsed arguments.
The argument string.
A ParsedArgumentsCollection containing the parsed arguments.
const parser = new ArgsParser([
{
name: 'action',
description: 'Action to perform',
type: 'string',
},
{
name: '--flag',
description: 'Flag',
alias: '-f',
type: 'boolean',
const: true,
default: false,
},
{
name: '--values',
description: 'Values',
alias: '-v',
type: 'string',
nargs: '*',
default: [],
}
]);
const argv = ['make', '--flag', '-v', 'a', 'b', 'c'];
const parsedArgs = parser.parse(argv);
console.log(parsedArgs.positional); // { action: 'make' }
console.log(parsedArgs.optional); // { flag: true, values: ['a', 'b', 'c'] }
console.log(parsedArgs.get('--values')); // ['a', 'b', 'c']
Parser for command-line arguments.