Files
Charlie Root 58f2e80eb5 update
2022-07-31 09:56:11 +00:00

23 lines
603 B
JavaScript

// examples/simple.js
// argv parse
Getopt = require('..');
// Getopt arguments options
// '=': has argument
// '[=]': has argument but optional
// '+': multiple option supported
getopt = new Getopt([
['s'],
['S' , '='],
['' , 'long-with-arg=ARG'],
['m' , '=+'],
['' , 'color[=COLOR]'],
['h' , 'help']
]).bindHelp();
// process.argv needs slice(2) for it starts with 'node' and 'script name'
// parseSystem is alias of parse(process.argv.slice(2))
// opt = getopt.parseSystem();
opt = getopt.parse(process.argv.slice(2));
console.info({argv: opt.argv, options: opt.options});