yargs-command-config

1.0.5

config

Yargs command for managing config files.

config
Parameters
options (Object = {}) options for this function.
Name Description
options.file string default path to JSON config file for yargs.
  • The command line argument [--config] will take priority over options.file
options.command string (default 'config') name of base <config> command.
  1. Original: config <task> [key] [value] [--config]
  2. options.command='newconfig': newconfig <task> [key] [value] [--config]
options.defaults Object (default {}) default config object to be used.
  • If options.defaults is undefined, the object argv.config will be used before defaulting to {}
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.
  1. Original: config <task> [key] [value] [--config]
  2. options.task.command='newtask': config <newtask> [key] [value] [--config]
options.task.key string (default 'key') name of optional [key] argument.
  1. Original: config <task> [key] [value] [--config]
  2. options.task.key='newkey': config <task> [newkey] [value] [--config]
options.task.value string (default 'value') name of optional [value] argument.
  1. Original: config <task> [key] [value] [--config]
  2. options.task.value='newvalue': config <task> [key] [newvalue] [--config]
options.task.config string (default 'config') name of optional [--config] argument.
  1. Original: config <task> [key] [value] [--config]
  2. options.task.config='newconfig': config <task> [key] [value] [--newconfig]
options.task.reset Object (default 'reset') name of <task > command for reset .
  1. Original: config reset [--config]
  2. options.task.reset='newreset': config newreset [--config]
options.task.clear Object (default 'clear') name of <task > command for clear .
  1. Original: config clear [--config]
  2. options.task.reset='newclear': config newclear [--config]
options.task.view Object (default 'view') name of <task > command for view .
  1. Original: config view [--config]
  2. options.task.view='newview': config newview [--config]
options.task.delete Object (default 'delete') name of <task > command for delete .
  1. Original: config delete [--config]
  2. options.task.delete='newdelete': config newdelete [key] [--config]
options.task.set Object (default 'set') name of <task > command for set .
  1. Original: config set [--config]
  2. options.task.set='newset': config newset [key] [value] [--config]
Returns
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
Example
// *** 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;