Yargs command for managing config files.
(Object
= {}
)
options for this function.
Name | Description |
---|---|
options.file string
|
default path to JSON config file for yargs.
|
options.command string
(default 'config' )
|
name of base
<config>
command.
|
options.defaults Object
(default {} )
|
default config object to be used.
|
options.describe string
(default 'describe' )
|
description for base
<config>
command.
|
options.task Object
(default {} )
|
options for
<task>
commands.
|
options.task.command Object
(default 'task' )
|
name of
<task>
command.
|
options.task.key string
(default 'key' )
|
name of optional
[key]
argument.
|
options.task.value string
(default 'value' )
|
name of optional
[value]
argument.
|
options.task.config string
(default 'config' )
|
name of optional
[--config]
argument.
|
options.task.reset Object
(default 'reset' )
|
name of
<task
> command for
reset
.
|
options.task.clear Object
(default 'clear' )
|
name of
<task
> command for
clear
.
|
options.task.view Object
(default 'view' )
|
name of
<task
> command for
view
.
|
options.task.delete Object
(default 'delete' )
|
name of
<task
> command for
delete
.
|
options.task.set Object
(default 'set' )
|
name of
<task
> command for
set
.
|
Object
:
Yargs
Command Module
with the following properties (
out
is the returned Object):
out.command
: the command string in the form of options.command <options.task.command> [options.task.key] [options.task.value] [--options.task.config]
out.describe
: the description string for out.command
out.handler
: the function that manages the config file and returns an argv
Object containing command line arguments// *** DEFAULT ***
var yargs = require('yargs');
// (config) Load command with path to config JSON file
var config = require('yargs-command-config')({file: './path/to/config.json'});
// (yargs) Add command to manage config file
var argv = yargs.command(config).argv;
// *** CUSTOM ***
var yargs = require('yargs');
// (options_command) Setup command options
options = {};
options.command = 'config2';
options.defaults = {field: 'value'};
options.describe = 'Description';
// (options_task) Setup task options
options.task = {};
options.task.command = 'task2';
options.task.key = 'key2';
options.task.value = 'value2';
options.task.config = 'config2';
options.task.reset = 'reset2';
options.task.clear = 'clear2';
options.task.view = 'view2';
options.task.delete = 'delete2';
options.task.set = 'set2';
// (config) Load command with options
var config = require('yargs-command-config')(options);
// (yargs) Add command to manage config file
var argv = yargs.command(config).argv;