yargs-command-env

0.0.0

env

Yargs command for managing env files.

env
Parameters
options (Object = {}) options for this function.
Name Description
options.file string default path to env file for yargs.
  • The command line argument [--env] will take priority over options.file
options.command string (default 'env') name of base <env> command.
  1. Original: env <task> [key] [value] [--env]
  2. options.command='newenv': newenv <task> [key] [value] [--env]
options.defaults Object (default {}) default env object to be used.
  • If options.defaults is undefined, the object argv.env will be used before defaulting to {}
options.describe string description for base <env> command.
options.task Object (default {}) options for <task> commands.
options.task.command Object (default 'task') name of <task> command.
  1. Original: env <task> [key] [value] [--env]
  2. options.task.command='newtask': env <newtask> [key] [value] [--env]
options.task.key string (default 'key') name of optional [key] argument.
  1. Original: env <task> [key] [value] [--env]
  2. options.task.key='newkey': env <task> [newkey] [value] [--env]
options.task.value string (default 'value') name of optional [value] argument.
  1. Original: env <task> [key] [value] [--env]
  2. options.task.value='newvalue': env <task> [key] [newvalue] [--env]
options.task.env string (default 'env') name of optional [--env] argument.
  1. Original: env <task> [key] [value] [--env]
  2. options.task.env='newenv': env <task> [key] [value] [--newenv]
options.task.reset Object (default 'reset') name of <task > command for reset .
  1. Original: env reset [--env]
  2. options.task.reset='newreset': env newreset [--env]
options.task.clear Object (default 'clear') name of <task > command for clear .
  1. Original: env clear [--env]
  2. options.task.reset='newclear': env newclear [--env]
options.task.view Object (default 'view') name of <task > command for view .
  1. Original: env view [--env]
  2. options.task.view='newview': env newview [--env]
options.task.delete Object (default 'delete') name of <task > command for delete .
  1. Original: env delete [--env]
  2. options.task.delete='newdelete': env newdelete [key] [--env]
options.task.set Object (default 'set') name of <task > command for set .
  1. Original: env set [--env]
  2. options.task.set='newset': env newset [key] [value] [--env]
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.env]
  • out.describe: the description string for out.command
  • out.handler: the function that manages the env file and returns an argv Object containing command line arguments
Example
// *** DEFAULT ***

var yargs = require('yargs');

// (env) Load command with path to env file
var env = require('yargs-command-env')({file: 'path/to/.env'});

// (yargs) Add command to manage env file
var argv = yargs.command(env).argv;

// *** CUSTOM ***

var yargs = require('yargs');

// (options_command) Setup command options
options = {};
options.file = 'path/to/.env';
options.command = 'env2';
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.env = 'env2';
options.task.reset = 'reset2';
options.task.clear = 'clear2';
options.task.view = 'view2';
options.task.delete = 'delete2';
options.task.set = 'set2';

// (env) Load command with options
var env = require('yargs-command-env')(options);

// (yargs) Add command to manage env file
var argv = yargs.command(env).argv;