Module: RatDeployer::Command
- Included in:
- Cli
- Defined in:
- lib/rat_deployer/command.rb
Overview
Rat::Deployer encapsulates all code related to running a shell command and displaying it’s output.
Instance Method Summary collapse
- #colorize_warning(str) ⇒ Object
- #do_run(cmd, silent: false) ⇒ Object
- #put_error(str) ⇒ Object
- #put_heading(str) ⇒ Object
- #put_warning(str) ⇒ Object
- #run(cmd, silent: false) ⇒ Object
Instance Method Details
#colorize_warning(str) ⇒ Object
52 53 54 |
# File 'lib/rat_deployer/command.rb', line 52 def colorize_warning(str) "\\\\ #{str}".colorize(:yellow) end |
#do_run(cmd, silent: false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rat_deployer/command.rb', line 21 def do_run(cmd, silent: false) output = '' status = 1 IO.popen(ENV, cmd) do |io| while line = io.gets # rubocop:disable Lint/AssignmentInCondition puts line unless silent output << line end io.close status = $CHILD_STATUS.to_i end { output: output, status: status } end |
#put_error(str) ⇒ Object
42 43 44 45 |
# File 'lib/rat_deployer/command.rb', line 42 def put_error(str) return unless RatDeployer::Config.prompt_enabled? puts "// #{str}".colorize(:red) end |
#put_heading(str) ⇒ Object
37 38 39 40 |
# File 'lib/rat_deployer/command.rb', line 37 def put_heading(str) return unless RatDeployer::Config.prompt_enabled? puts "|| #{str}".colorize(:blue) end |
#put_warning(str) ⇒ Object
47 48 49 50 |
# File 'lib/rat_deployer/command.rb', line 47 def put_warning(str) return unless RatDeployer::Config.prompt_enabled? puts colorize_warning(str) end |
#run(cmd, silent: false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rat_deployer/command.rb', line 10 def run(cmd, silent: false) if !silent && RatDeployer::Config.prompt_enabled? puts '||=> Running command '.colorize(:blue) + "`#{cmd.colorize(:white)}`" end command = do_run(cmd, silent: silent) exit 1 unless command.fetch(:status).zero? command end |