Simpleton
Node.js command line argument parser with command callback support.
Uses minimist to parse command line arguments, see it's documentation for available argument options.
Usage
Using simpleton
is as easy as defining command callback methods and command
line argument options.
Example usage from examples/example.js
:
var simpleton = ; var options = // options used to parse arguments before command alias: help: 'h' boolean: 'help' // command callbacks and argument options commands: list: alias: file: 'f' default: file: 'test-file.txt' { console; } help: { console; } inheritCommon: true // if true, extend command options with common options; var command = ; // example command object content/*{ name: 'list', common: { ... }, // arguments parsed before command args: { ... }, // arguments parsed after command exec: [Function], // method to execute commands callback method}*/ console;console;console;console;command;
Example output with different arguments:
> node examples/example.js -h
Command: undefined
Common: { _: [], help: true, h: true }
Args: { _: [], help: false, h: false }
> node examples/example.js list -h -f file.txt
Command: list
Common: { _: [ 'list', '-h', '-f', 'file.txt' ], help: false, h: false }
Args: { _: [], help: false, h: true, f: 'file.txt', file: 'file.txt' }
Running 'list' command with { '0': { _: [], help: false, h: true, f: 'file.txt', file: 'file.txt' }, '1': { '0': 'extra argument' } }
> node examples/example.js help
Command: help
Common: { _: [ 'help' ], help: false, h: false }
Args: { _: [], help: false, h: false }
HELP!