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.



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

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.



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

def cmd
  @cmd
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

Instance Method Details

#escape_cmdObject



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

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

#messageObject



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

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