Class: Shred::Commands::ShellCommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/shred/commands/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(console: console) ⇒ ShellCommandRunner

Returns a new instance of ShellCommandRunner.



90
91
92
# File 'lib/shred/commands/base.rb', line 90

def initialize(console: console)
  @console = console
end

Instance Attribute Details

#consoleObject (readonly)

Returns the value of attribute console.



88
89
90
# File 'lib/shred/commands/base.rb', line 88

def console
  @console
end

Instance Method Details

#run(shell_command) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/shred/commands/base.rb', line 94

def run(shell_command)
  exit_status = shell_command.run do |command_line|
    console.say_trace(command_line)
    command_line.run
  end
  if exit_status.success?
    if shell_command.success_msg
      console.say_ok(shell_command.success_msg)
    end
  elsif
    if shell_command.error_msg
      console.say_err("#{shell_command.error_msg}: #{exit_status}")
    else
      console.say_err(exit_status)
    end
  end
end