Exception: Licensed::Shell::Error

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

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
  @output = stderr
end

Instance Method Details

#escape_cmdObject



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

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
47
# File 'lib/licensed/shell.rb', line 43

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