Class: Joumae::Command
- Inherits:
-
Object
- Object
- Joumae::Command
- Defined in:
- lib/joumae/command.rb
Constant Summary collapse
- EXIT_STATUS_INTERRUPT =
130
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
Instance Method Summary collapse
-
#initialize(cmd, resource_name:, client:) ⇒ Command
constructor
A new instance of Command.
- #logger ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(cmd, resource_name:, client:) ⇒ Command
Returns a new instance of Command.
12 13 14 15 16 |
# File 'lib/joumae/command.rb', line 12 def initialize(cmd, resource_name:, client:) @cmd = cmd @resource_name = resource_name @client = client end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
10 11 12 |
# File 'lib/joumae/command.rb', line 10 def cmd @cmd end |
Instance Method Details
#logger ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/joumae/command.rb', line 18 def logger @logger ||= Logger.new(STDOUT).tap do |logger| log_level_from_env = ENV['JOUMAE_LOG_LEVEL'] || 'INFO' logger.level = Logger.const_get(log_level_from_env) logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") "#{cmd} (#{severity}): #{msg}\n" end end end |
#run! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/joumae/command.rb', line 29 def run! status = Joumae::Transaction.run!(resource_name: @resource_name, client: @client) do Open3.popen3(cmd) do |i, o, e, w| unless STDIN.tty? redirect(STDIN => i) end i.close redirect(o => STDOUT, e => STDERR) debug w.value w.value.exitstatus end end raise Joumae::CommandFailedError.new("Exit status(=#{status}) is non-zero.", status) if status != 0 end |