bagofcli

bagofcli module.
Source:

Methods

(inner) command(base, actions, optsopt) → {void}

Parse command line arguments and execute actions based on the specified commands. Uses commander.js to provide -V / --version to be displayed version number, and -h / --help to be displayed help info.
Source:
Parameters:
Name Type Attributes Description
base string Base directory where the client module is located. Used as the root directory to read the command file and package.json file. Ideally this is the client's `__dirname`.
actions Object Action functions for commands in the form `{ command: { action: function () {} } }`. The command name in `actions` is mapped to the command name specified in `commandFile`.
opts Object <optional>
Optional settings.
Name Type Attributes Default Description
commandFile string <optional>
'conf/commands.json' Relative path to the command file from `base`.
Returns:
Type:
void

(inner) exec(command, fallthrough, cb) → {void}

Execute a one-liner command. The output emitted on stderr and stdout of the child process will be written to process.stdout and process.stderr of this process. Fallthrough is handy in situation where there are multiple execs running in sequence/parallel, and they all have to be executed regardless of success/error on either one of them.
Source:
Parameters:
Name Type Description
command string Command to execute.
fallthrough boolean Allow error to be camouflaged as a non-error.
cb function Standard `cb(err, result)` callback.
Returns:
Type:
void

(inner) execAndCollect(command, fallthrough, cb) → {void}

Execute a one-liner command and collect the output. The output emitted on stderr and stdout of the child process will be collected and passed on to the given callback. Fallthrough is handy in situation where there are multiple execs running in sequence/parallel, and they all have to be executed regardless of success/error on either one of them.
Source:
Parameters:
Name Type Description
command string Command to execute.
fallthrough boolean Allow error to be camouflaged as a non-error.
cb function `(err, stdOutOutput, stdErrOutput, result)` callback.
Returns:
Type:
void

(inner) exit(err) → {void}

Handle process exit based on the existence of error. This is handy for command-line tools to use as the final callback. Exit status code 1 indicates an error, exit status code 0 indicates a success. Error message will be logged to the console. Result object is only used for convenient debugging. Exit is also called with a second method in the signature called 'result', but it's not declared here due to not being used when there is no error and this function simply exits with code 0
Source:
Parameters:
Name Type Description
err Error Error object existence indicates the occurrence of an error.
Returns:
Type:
void

(inner) exitCb(errorCbopt, successCbopt) → {function}

A higher order function that returns a process exit callback, with error and success callbacks to handle error and result accordingly. Exit status code 1 indicates an error, exit status code 0 indicates a success.
Source:
Parameters:
Name Type Attributes Description
errorCb function <optional>
Error callback, defaults to logging to console error.
successCb function <optional>
Success callback, defaults to logging to console log.
Returns:
Type:
function
Exit callback.

(inner) files(items, optsopt) → {Array.<string>}

Get an array of files contained in specified items. When a directory is specified, all files contained within that directory and its sub-directories will be included.
Source:
Parameters:
Name Type Attributes Description
items Array.<string> Array of files and/or directories.
opts Object <optional>
Optional settings.
Name Type Attributes Description
match string <optional>
Regular expression to match against the file name.
Returns:
Type:
Array.<string>
All files.

(inner) logStepHeading(message, optsopt) → {void}

Displays log step heading message on the console.
Source:
Parameters:
Name Type Attributes Description
message string Heading message to be displayed.
opts Object <optional>
Optional settings.
Name Type Attributes Description
labels Array.<string> <optional>
Labels to be displayed before the message.
Returns:
Type:
void

(inner) logStepItemError(message, optsopt) → {void}

Displays log step error item error message on the console.
Source:
Parameters:
Name Type Attributes Description
message string Error message to be displayed.
opts Object <optional>
Optional settings.
Name Type Attributes Description
labels Array.<string> <optional>
Labels to be displayed before the message.
Returns:
Type:
void

(inner) logStepItemSuccess(message, optsopt) → {void}

Displays log step item success message on the console.
Source:
Parameters:
Name Type Attributes Description
message string Success message to be displayed.
opts Object <optional>
Optional settings.
Name Type Attributes Description
labels Array.<string> <optional>
Labels to be displayed before the message.
Returns:
Type:
void

(inner) logStepItemWarning(message, optsopt) → {void}

Displays log step item warning message on the console.
Source:
Parameters:
Name Type Attributes Description
message string Warning message to be displayed.
opts Object <optional>
Optional settings.
Name Type Attributes Description
labels Array.<string> <optional>
Labels to be displayed before the message.
Returns:
Type:
void

(inner) lookupConfig(keys, opts, cb) → {void}

Lookup config values for the specified keys in the following order: - environment variable - if optional file is specified, then check for the value inside the file file type depends on extension file - if optional enablePrompt is set to true, then prompt the user for config value
Source:
Parameters:
Name Type Description
keys Array.<string> | string Configuration keys to look up.
opts Object Optional settings.
Name Type Attributes Default Description
file string <optional>
File name to look up configuration values from.
prompt boolean <optional>
false Prompt the user for missing configuration values.
cb function Standard `cb(err, result)` callback.
Returns:
Type:
void

(inner) lookupFile(file, optsopt) → {string}

Synchronously read file based on these rules: - if path is absolute, then check file at absolute path first - if path is relative, then check file at current working directory - if none of the above exists, check file at user home directory - if none exists, throw an error This allows simple file lookup which allows various locations.
Source:
Parameters:
Name Type Attributes Description
file string File name to read.
opts Object <optional>
Optional settings.
Name Type Attributes Description
platform string <optional>
Platform override for tests.
Returns:
Type:
string
File content.

(inner) spawn(command, args, cb) → {void}

Execute a command with an array of arguments. E.g. command: make, arguments: -f somemakefile target1 target2 target3 will be executed as: make -f somemakefile target1 target2 target3 NOTE: process.stdout.write and process.stderr.write are used because console.log adds a newline
Source:
Parameters:
Name Type Description
command string Command to execute.
args Array.<string> Command arguments.
cb function Standard `cb(err, result)` callback.
Returns:
Type:
void