shell

Contains functions to exec commands.

Since: 3.0.0
Example

// Run a docker compose command
return lando.shell.sh([COMPOSE_EXECUTABLE].concat(cmd), opts);

// Determine the location of the 'docker' command
var which = lando.shell.which(DOCKER_EXECUTABLE);

// Escape spaces in a command before it is exece
var cmd = lando.shell.escSpaces(opts.entrypoint.join(' '));

// Escape a command to make it more cli friendly before it is exece
var cmd = lando.shell.esc(cmd);

shell.esc ⇒ String

Escapes special characters in a command to make it more exec friendly.

Kind: static method of shell
Returns: String - The escaped cmd.
Since: 3.0.0

Param Type Description
cmd Array A command as elements of an Array or a String.

Example

// Escape the cmd
var escapedCmd = lando.shell.esc(['git', 'commit', '-m', 'my message']);

shell.which ⇒ String | undefined

Returns the path of a specific command or binary.

Kind: static method of shell
Returns: String | undefined - The path to the command or undefined.
Since: 3.0.0

Param Type Description
cmd String A command to search for.

Example

// Determine the location of the 'docker' command
var which = lando.shell.which(DOCKER_EXECUTABLE);

shell.sh(cmd, [opts]) ⇒ Promise

Runs a command.

This is an abstraction method that:

  1. Delegates to either node's native spawn or exec methods.
  2. Promisifies the calling of these function
  3. Handles stdout, stdin and stderr

Beyond the options specified below you should be able to pass in known exec or spawn options depending on whether we have a mode or not.

Kind: static method of shell
Returns: Promise - A promise with collected results if applicable.
See

Since: 3.0.0

Param Type Description
cmd Array The command to run as elements in an array or a string.
[opts] Object Options to help determine how the exec is run.
[opts.mode] String The mode, typically collect or attach;
[opts.detached] Boolean Whether we are running in detached mode or not

Example

// Run a command in collect mode
return lando.shell.sh(['ls', '-lsa', '/'], {mode: 'collect'})

// Catch and log any errors
.catch(function(err) {
  lando.log.error(err);
})

// Print the collected results of the command
.then(function(results) {
  console.log(results);
});

shell.escSpaces(s) ⇒ String

Escapes any spaces in a command.

Kind: static method of shell
Returns: String - The space escaped cmd.
Since: 3.0.0

Param Type Description
s Array A command as elements of an Array or a String.

Example

// Escape the spaces in the cmd
var escapedCmd = lando.shell.escSpaces(['git', 'commit', '-m', 'my message']);

results matching ""

    No results matching ""