Utility functions global to The Clusternator

Source:

Methods

(inner) cliErr(operationDescription, maps)

Intended to handle errors at the CLI level.

Pretty-prints messages for specific error codes and decides whether to exit with 0 or 1.

Parameters:
Name Type Description
operationDescription string

Describes what's being done in the CLI.

maps codeMap

error codes to messages.

If codeMap is omitted, or doesn't match an actual error, error.message will be logged instead.

Example:

.fail(cliErr('Doing something with clusternator', { ENOENT: { msg: 'something not found', code: 1 }, EACCES: { msg: 'no big deal' } }));

Source:

(inner) cliLogger(yargs)

Sets up verbosity for the CLI

Parameters:
Name Type Description
yargs Object
Source:
To Do:
  • move this function into the CLI api, or somewhere else

(inner) clone(obj) → {*}

Quick/dirty deep copy. Will break on circular structures.

Parameters:
Name Type Description
obj *
Source:
Returns:

copy

Type
*

(inner) debug()

logs a debug message(s) through winston (takes any args)

Source:

(inner) deepFreeze(obj) → {Object}

Makes an object and its parts immutable

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Object

(inner) errLog(x) → {Promise}

Logs an info error labelled as error, and returns a Promise

Parameters:
Name Type Description
x *
Source:
Returns:
Type
Promise

(inner) error()

logs an error message(s) through winston (takes any args)

Source:

(inner) getCidrPrefixFromIPString(ip) → {string}

Parameters:
Name Type Description
ip string

something like: '1.2.3.0/24'

Source:
Returns:

first two classes, like: '1.2'

Type
string

(inner) info()

logs an info message(s) through winston (takes any args)

Source:

(inner) initWinston()

Starts up the winston logger for STDIO

Source:

(inner) inquirerPrompt(qs, onEachAnsweropt, onEachErroropt, onCompleteopt) → {Promise}

Uses inquirer to prompt for STDIO input/output

Parameters:
Name Type Attributes Description
qs Array
onEachAnswer function <optional>
onEachError function <optional>
onComplete function <optional>
Source:
To Do:
  • move this to a CLI utility section
Returns:
Type
Promise

(inner) isFunction(fn) → {boolean}

Is the given argument a function?

Parameters:
Name Type Description
fn *

to test

Source:
Returns:
Type
boolean

(inner) isObject(i) → {boolean}

Parameters:
Name Type Description
i *
Source:
Returns:
Type
boolean

(inner) makePromiseApi(api) → {Object}

Shallow iterates over a given object and assumes all functions are node callback style and converts them to Promises NOTE* this function now produces promises that timeout based on the value in constants.PROMISE_API_TIMEOUT. Clusternator only uses this function to wrap AWS APIs that callback within (typically) a few seconds

Parameters:
Name Type Description
api Object

some collection/object of nodejs style functions

Source:
Returns:

a new object with promisified functions

Type
Object

(inner) makeRetryPromiseFunction(promiseReturningFunction, retryCount, delayopt, multiplieropt, failOn, labelopt) → {function}

Parameters:
Name Type Attributes Description
promiseReturningFunction function
retryCount number

times to retry

delay number <optional>

ms to delay retry

multiplier number <optional>

each failure will multiply the delay by this

failOn function

if true fails instead of retrying

label string <optional>
Source:
Returns:
Type
function

(inner) nTimeoutBindFnTo(fn, api, messageopt) → {function}

Parameters:
Name Type Attributes Description
fn function
api Object
message string <optional>
Source:
Returns:
Type
function

(inner) partial(fn, args) → {applyPartial}

Partially applies a function using references

Parameters:
Name Type Description
fn function
args Array.<*> | *
Source:
Returns:
Type
applyPartial

(inner) plog() → {*}

Deprecated:
  • Yes
Source:
Returns:
Type
*

(inner) prefixError(err, prefix) → {Error}

Parameters:
Name Type Description
err Error
prefix string
Source:
Returns:
Type
Error

(inner) quote(str) → {string}

Double quote something

Parameters:
Name Type Description
str string
Source:
Returns:

(double) quoted version

Type
string

(inner) safeParse(string) → {null|*}

Parameters:
Name Type Description
string string
Source:
Returns:
Type
null | *

(inner) validSlackChannel(channel) → {boolean}

Parameters:
Name Type Description
channel string
Source:
Returns:
Type
boolean

(inner) verbose()

logs a verbose message(s) through winston (takes any args)

Source:

(inner) waitFor(asyncPredicateFunction, interval, maxopt, labelopt) → {Promise}

Wait function for polling something.

Provide a function a that uses a promise to check something asynchronously. This "asyncPredicateFunction" should resolve when it's "ready" to proceed, and reject if it is not ready.

Parameters:
Name Type Attributes Description
asyncPredicateFunction function

should resolve when its condition is eventually satisfied, and reject otherwise

interval number

ms to retry asyncPredicateFunction (defaults to 10000)

max number <optional>

maximum number of retries (default 0 for infinity)

label string <optional>

label for debugging

Source:
Returns:
Type
Promise

(inner) warn()

logs a warning message(s) through winston (takes any args)

Source: