Class: RightConf::Command

Inherits:
Object
  • Object
show all
Includes:
ProgressReporter, Singleton
Defined in:
lib/rconf/command.rb

Instance Method Summary collapse

Methods included from ProgressReporter

included, report_to_file, report_to_stdout

Methods included from Singleton

included

Instance Method Details

#execute(command, *args) ⇒ Object

Execute given command with given arguments

Parameters

command(String)

Command to run

args(Array)

Command arguments

Return

result(CommandResult)

Result of execution (output and exit status)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rconf/command.rb', line 29

def execute(command, *args)
  opts = {}
  if !args.empty? && args[-1].is_a?(Hash)
    opts = args[-1]
    args = args[0..-2]
  end
  res = Platform.dispatch(command, *args) { :execute }
  if @verbose
    msg = (([@prefix, command] + args).compact.join(' ') + ' => ' +
      res.status.to_s + ': ' + res.output).grey
    report(msg)
  end
  if !res.success? && msg = opts[:abort_on_failure]
    report_fatal("#{msg}: '#{command} #{args.join(' ')}' returned\n#{res.output}")
  end
  res
end

#execute_linux(command, *args) ⇒ Object Also known as: execute_darwin

Execute given command on *nix systems

Parameters

command(String)

Command name

params(Array)

List of parameters to pass to command

Return

result(CommandResult)

Result of execution (output and exit status)



55
56
57
58
# File 'lib/rconf/command.rb', line 55

def execute_linux(command, *args)
  out = `#{@prefix} #{Shellwords.join([command, *args])} 2>&1`
  result = CommandResult.new(out, $?.exitstatus)
end

#execute_windows(command, *args) ⇒ Object

Execute given command on Windows systems

Parameters

command(String)

Command name

params(Array)

List of parameters to pass to command

Return

result(CommandResult)

Result of execution (output and exit status)



69
70
71
# File 'lib/rconf/command.rb', line 69

def execute_windows(command, *args)
  raise 'TBD!'
end

#set_prefix(prefix) ⇒ Object

Set prefix to be used for all commands

Parameters

prefix(String)

Commands prefix

Return

true

Always return true



80
81
82
83
# File 'lib/rconf/command.rb', line 80

def set_prefix(prefix)
  @prefix = prefix
  true
end

#set_verboseObject

Enable debug output

Return

true

Always return true



89
90
91
# File 'lib/rconf/command.rb', line 89

def set_verbose
  @verbose = true
end