Method: RightDevelop::Utility::Shell#execute

Defined in:
lib/right_develop/utility/shell.rb

#execute(cmd, options = {}) ⇒ Integer

Overrides ::RightGit::Shell::Default#execute

Parameters:

  • cmd (String)

    the shell command to run

  • options (Hash) (defaults to: {})

    for execution

Options Hash (options):

  • :directory (String)

    to use as working directory during command execution or nil

  • :logger (Logger)

    logger for shell execution (default = STDOUT)

  • :outstream (IO)

    output stream to receive STDOUT and STDERR from command (default = none)

  • :raise_on_failure (TrueClass|FalseClass)

    if true, wil raise a RuntimeError if the command does not end successfully (default), false to ignore errors

  • :set_env_vars (Hash)

    environment variables to set during execution (default = none set)

  • :clear_env_vars (Hash)

    environment variables to clear during execution (default = none cleared but see :clean_bundler_env)

  • :clean_bundler_env (TrueClass|FalseClass)

    true to clear all bundler environment variables during execution (default), false to inherit bundler env from parent

  • :sudo (TrueClass|FalseClass)

    if true, will wrap command in sudo if needed, false to run as current user (default)

Returns:

  • (Integer)

    exitstatus of the command

Raises:

  • (ShellError)

    on failure only if :raise_on_failure is true



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/right_develop/utility/shell.rb', line 99

def execute(cmd, options = {})
  options = {
    :clean_bundler_env => true,
    :sudo              => false
  }.merge(options)

  if options[:sudo]
    fail "Not available in Windows" if is_windows?
    cmd = "sudo #{cmd}" unless ::Process.euid == 0
  end

  # super execute.
  super(cmd, options)
end