Skip to main content

Return Object

An object returned to the CLI from a script may be automatically formatted, depending on its contents. These types of objects are often referred to as Success or Failure objects.

Syntax

A Success or Failure object can only contain two keys. The ok key is required, and determines whether Success or Failure is displayed in the terminal. You may also attach a msg key, which will append that value, after being converted to a string.

Example

function(context, args) {
//Explains the guessing game when the script is run without a guess.
if (!args.guess) {
return "Let's play a guessing game! Guess a number between 1 and 10!"
}

//Return a success object if they guess they right number.
if (args.guess == Math.floor(Math.random() * 10)) {
return {
ok: true,
msg: args.guess + " was the right number!"
}
}

//In all other cases, return a failure object.
return {
ok: false,
msg: "Sorry, please guess again!"
}
}

See Also