minimist-subcommand
A simple sub-command parser for minimist
Installation
npm install minimist-subcommand
Examples
Basic
basic.js
:
const parseArgs = ;const parseCommands = ; // parse sub-commandsconst commandDefinition = commands: foo: null bar: null ;const parsedCommandsAndArgv = ; // pass parsed argv to minimistconst options = ; console;console;
$ node ./basic.js foo arg -a -b val -csub-command: [ 'foo' ]parsed options by minimist:
$ node ./basic.js arg -asub-command: []parsed options by minimist:
$ node ./basic.js bar foosub-command: [ 'bar' ]parsed options by minimist:
Nested commands
nested-commands.js
:
const parseArgs = ;const parseCommands = ; // parse sub-commandsconst commandDefinition = commands: singleton: null married: commands: child: commands: grandchild: null ;const parsedCommandsAndArgv = ; // pass parsed argv to minimistconst options = ; console;console;
$ node ./nested-commands.js married child grandchild arg -acommands: [ 'married', 'child', 'grandchild' ]parsed options by minimist:
$ node ./nested-commands.js singleton child grandchildcommands: [ 'singleton' ]parsed options by minimist:
Use "default" option
use-default-option.js
:
const parseArgs = ;const parseCommands = ; // parse sub-commandsconst commandDefinition = default: 'bar' commands: foo: null bar: null ;const parsedCommandsAndArgv = ; // pass parsed argv to minimistconst options = ; console;console;
$ node ./use-default-option.js arg -asub-command: [ 'bar' ]parsed options by minimist:
Command's Schema
If you want to check schema of commandDefinition
, please use COMMAND_JSON_SCHEMA
.
const COMMAND_JSON_SCHEMA = COMMAND_JSON_SCHEMA; const commandDefinition = commands: foo: null bar: null ; // I will leave it to the judgment of the user.someJsonSchemaLibrary;