Module: Superhosting::Helper::Cmd
- Included in:
- DockerApi, Superhosting::Helpers
- Defined in:
- lib/superhosting/helper/cmd.rb
Instance Method Summary collapse
- #_command(*command_args, debug: true, logger: nil, &b) ⇒ Object
- #_command_without_debug(*command_args) ⇒ Object
- #command(*command_args, **kwargs) ⇒ Object
- #command!(*command_args, **kwargs) ⇒ Object
Instance Method Details
#_command(*command_args, debug: true, logger: nil, &b) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/superhosting/helper/cmd.rb', line 14 def _command(*command_args, debug: true, logger: nil, &b) self.with_logger(logger: logger) do desc = { code: :command, data: { command: command_args.join } } if debug self.debug_operation(desc: desc) do |&blk| self._command_without_debug(*command_args, &b) blk.call(code: :ok) end else self._command_without_debug(*command_args, &b) end {} # net_status end end |
#_command_without_debug(*command_args) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/superhosting/helper/cmd.rb', line 29 def _command_without_debug(*command_args) self.with_dry_run do |dry_run| unless dry_run cmd = Mixlib::ShellOut.new(*command_args) cmd.run_command yield cmd if block_given? and !cmd.status.success? end end end |
#command(*command_args, **kwargs) ⇒ Object
10 11 12 |
# File 'lib/superhosting/helper/cmd.rb', line 10 def command(*command_args, **kwargs) self._command(command_args, **kwargs) end |
#command!(*command_args, **kwargs) ⇒ Object
4 5 6 7 8 |
# File 'lib/superhosting/helper/cmd.rb', line 4 def command!(*command_args, **kwargs) self._command(*command_args, **kwargs) do |cmd| raise NetStatus::Exception.new(error: :error, code: :command_with_error, data: { error: [cmd.stdout, cmd.stderr].join("\n") }) end end |