A simple args parser
$ npm install --save argi
const argi = require('argi');
// Options
argi.option('name', 'description', { default: 'bob', aliases: 'n', boolean: false, hidden: false });
// Commands
argi.command('sayhi', 'description', { hidden: false });
// Parse argv
const parsed = argi.parse(process.argv.slice(2));
if (parsed.sayhi) {
console.log(`Hi ${ parsed.name }!`);
} else {
console.log(args.help());
}
Type: string
The option's name.
Type: string
What the option does. Will be used for help.
Type: object
Type: string
The options default value.
Type: string
, array
Alias names for the option.
Type: boolean
Default: false
Specifies whether the option is a boolean(true
/false
) or a string. If set to true arguments after the option will count as a command or as a separate option.
Example:
...
argi.option('boolean', 'description', { boolean: true });
const parsed = argi.parse(['--boolean', 'value'])
parsed.boolean // => true
parsed._ // => ['value']
...
hidden
Type: boolean
Default: false
If option should be displayed in help.
Type: string
The command's name.
Type: string
What the command does. Will be used for help.
Type: object
hidden
Type: boolean
Default: false
If command should be displayed in help.
Returns a help string. Will throw an error if it's called before argi.parse()
An array of cli options. You should probably set it to process.argv.slice(2)
Returns an object with the option's values and if commands should be executed.
Example:
...
const parsed = argi.parse(['--test', '--opt', 'yes', 'build']);
// => {
// => test: true,
// => opt: 'yes',
// => build: true
// => }
...
MIT © Tobias Herber