Class: Scripto::RunCommands::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/scripto/run_commands.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, args) ⇒ CommandLine

Returns a new instance of CommandLine.



61
62
63
64
65
66
67
68
# File 'lib/scripto/run_commands.rb', line 61

def initialize(command, args)
  self.command = command
  self.args = if args
    args.map(&:to_s)
  else
    [ ]
  end
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



59
60
61
# File 'lib/scripto/run_commands.rb', line 59

def args
  @args
end

#commandObject

Returns the value of attribute command.



59
60
61
# File 'lib/scripto/run_commands.rb', line 59

def command
  @command
end

Instance Method Details

#captureObject



75
76
77
78
79
80
81
82
83
# File 'lib/scripto/run_commands.rb', line 75

def capture
  begin
    captured = `#{to_s}`
  rescue Errno::ENOENT
    raise Error, "#{self} failed : ENOENT (No such file or directory)"
  end
  raise!($CHILD_STATUS) if $CHILD_STATUS != 0
  captured
end

#raise!(status) ⇒ Object

Raises:



85
86
87
88
89
90
# File 'lib/scripto/run_commands.rb', line 85

def raise!(status)
  if status.termsig == Signal.list["INT"]
    raise "#{self} interrupted"
  end
  raise Error, "#{self} failed : #{status.to_i / 256}"
end

#runObject



70
71
72
73
# File 'lib/scripto/run_commands.rb', line 70

def run
  system(command, *args)
  raise!($CHILD_STATUS) if $CHILD_STATUS != 0
end

#to_sObject



92
93
94
95
96
97
98
99
# File 'lib/scripto/run_commands.rb', line 92

def to_s
  if args.length > 0
    escaped = args.map { |i| Shellwords.escape(i) }
    "#{command} #{escaped.join(" ")}"
  else
    command
  end
end