Exception: Licensed::Shell::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/licensed/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, status, stderr) ⇒ Error

Returns a new instance of Error.



36
37
38
39
40
41
# File 'lib/licensed/shell.rb', line 36

def initialize(cmd, status, stderr)
  super()
  @cmd = cmd
  @exitstatus = status
  @stderr = stderr.to_s.strip
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



35
36
37
# File 'lib/licensed/shell.rb', line 35

def cmd
  @cmd
end

#statusObject (readonly)

Returns the value of attribute status.



35
36
37
# File 'lib/licensed/shell.rb', line 35

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



35
36
37
# File 'lib/licensed/shell.rb', line 35

def stderr
  @stderr
end

Instance Method Details

#escape_cmdObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/licensed/shell.rb', line 48

def escape_cmd
  @cmd.map do |arg|
    if arg =~ /[\s'"]/
      escaped = arg.gsub(/([\\"])/, '\\\\\1')
      %("#{escaped}")
    else
      arg
    end
  end.join(" ")
end

#messageObject



43
44
45
46
# File 'lib/licensed/shell.rb', line 43

def message
  extra = @stderr.empty?? "" : "#{@stderr.gsub(/^/, "        ")}"
  "'#{escape_cmd}' exited with status #{@exitstatus}\n#{extra}"
end