Module: Rubbr::Cli
- Included in:
- Builder, Builder::Base, Options, Runner::Base, Scm::Base, Spell, Viewer::Base
- Defined in:
- lib/rubbr/cli.rb
Overview
Handles command line output and input.
Instance Method Summary collapse
- #color?(msg, code) ⇒ Boolean
- #disable_stderr ⇒ Object
- #disable_stdinn ⇒ Object
- #disable_stdout ⇒ Object
- #error(message) ⇒ Object
- #executable?(executable) ⇒ Boolean
- #notice(message) ⇒ Object
- #valid_executable(executable) ⇒ Object
- #warning(message) ⇒ Object
Instance Method Details
#color?(msg, code) ⇒ Boolean
17 18 19 |
# File 'lib/rubbr/cli.rb', line 17 def color?(msg, code) Rubbr.[:color] ? "#{code}#{msg}\e[0m" : msg end |
#disable_stderr ⇒ Object
28 29 30 31 32 33 |
# File 'lib/rubbr/cli.rb', line 28 def disable_stderr old_stderr = STDERR.dup STDERR.reopen('/dev/null') yield STDERR.reopen(old_stderr) end |
#disable_stdinn ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rubbr/cli.rb', line 35 def disable_stdinn old_stdinn = STDIN.dup STDIN.reopen('/dev/null') yield STDIN.reopen(old_stdinn) end |
#disable_stdout ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rubbr/cli.rb', line 21 def disable_stdout old_stdout = STDOUT.dup STDOUT.reopen('/dev/null') yield STDOUT.reopen(old_stdout) end |
#error(message) ⇒ Object
13 14 15 |
# File 'lib/rubbr/cli.rb', line 13 def error() puts color?(" * #{}", "\e[31m") end |
#executable?(executable) ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/rubbr/cli.rb', line 42 def executable?(executable) disable_stdout do @existing = system("which #{executable}") end @existing end |
#notice(message) ⇒ Object
5 6 7 |
# File 'lib/rubbr/cli.rb', line 5 def notice() puts color?(, "\e[32m") if Rubbr.[:verbose] end |
#valid_executable(executable) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rubbr/cli.rb', line 49 def valid_executable(executable) if executable?(executable) executable else error "Missing executable #{executable}" exit end end |
#warning(message) ⇒ Object
9 10 11 |
# File 'lib/rubbr/cli.rb', line 9 def warning() puts color?(" - #{}", "\e[33m") if Rubbr.[:verbose] end |