nested-opts
Deeply nested command line options parser
Example
cli.js
var nested = require('nested-opts')
var config = {
commands: {
server: {
commands: {
add: {
options: {
host: { type: 'String' },
port: { type: 'Int' }
}
},
update: {
options: {
id: { type: 'String' },
host: { type: 'String' },
port: { type: 'Int' }
}
}
},
options: {
help: true
}
}
}
}
var opts = nested(config)
console.log(opts)
/*
> node cli.js server add host localhost port 8080
{
valid: true,
args: ['server', 'add', 'host', 'localhost', 'port', '8080'],
command: 'server',
options: false,
subcommand: {
command: 'add',
options: {
host: 'localhost',
port: 8080
}
}
}
> node cli.js server help
{
valid: true,
args: ['server', 'help'],
command: 'server',
options: {
help: true
}
}
*/
API
nested
( config
)
Parameters
-
config
{Object
}- [
options
] {Object
}- [
silent=false
] {Boolean
} - When true do not print output - [
error
] {Function
} - Custom error printing function
- [
-
commands
{CommandList
}
- [
Returns NestedOutput
Types
CommandList
[commandName] : {
commands: [CommandList],
options: [OptionList]
}
OptionList
[optionName]: OptionConfig | true
OptionConfig
{
type: OptionTypeEnum
}
OptionTypeEnum
'String' | 'Number' | 'Int' | 'Array' | 'JSON' | 'Date'
KeyValuePair
[key]: Any
NestedOutput
{
args: Array<String>,
valid: Boolean,
command: String,
options: {
KeyValuePair
},
subcommand: {
options: {
KeyValuePair
},
subcommand: { ... }
}
}