Module: RatDeployer::Command
- Included in:
- Cli
- Defined in:
- lib/rat_deployer/command.rb
Instance Method Summary collapse
- #ask_for_confirmation ⇒ Object
- #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
#ask_for_confirmation ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rat_deployer/command.rb', line 48 def ask_for_confirmation return unless RatDeployer::Config.prompt_enabled? prompt = "Are you sure you want to continue?" a = '' s = '[y/n]' d = 'y' until %w[y n].include? a a = ask(colorize_warning("#{prompt} #{s} ")) { |q| q.limit = 1; q.case = :downcase } a = d if a.length == 0 end exit 1 unless a == 'y' end |
#colorize_warning(str) ⇒ Object
64 65 66 |
# File 'lib/rat_deployer/command.rb', line 64 def colorize_warning(str) "\\\\ #{str}".colorize(:yellow) end |
#do_run(cmd, silent: false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rat_deployer/command.rb', line 18 def do_run(cmd, silent: false) output, status = '', 1 IO.popen(cmd) do |io| while line = io.gets do puts line unless silent output << line end io.close status = $?.to_i end {output: output, status: status} end |
#put_error(str) ⇒ Object
38 39 40 41 |
# File 'lib/rat_deployer/command.rb', line 38 def put_error(str) return unless RatDeployer::Config.prompt_enabled? puts "// #{str}".colorize(:red) end |
#put_heading(str) ⇒ Object
33 34 35 36 |
# File 'lib/rat_deployer/command.rb', line 33 def put_heading(str) return unless RatDeployer::Config.prompt_enabled? puts "|| #{str}".colorize(:blue) end |
#put_warning(str) ⇒ Object
43 44 45 46 |
# File 'lib/rat_deployer/command.rb', line 43 def put_warning(str) return unless RatDeployer::Config.prompt_enabled? puts colorize_warning(str) end |
#run(cmd, silent: false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rat_deployer/command.rb', line 7 def run(cmd, silent: false) if !silent && RatDeployer::Config.prompt_enabled? msg = "||=> Running command ".colorize(:blue) + "`#{cmd.colorize(:white)}`" puts msg end command = do_run(cmd, silent: silent) exit 1 unless command.fetch(:status).zero? command end |