Module: Rubbr::Cli
- Includes:
- OS
- 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
Methods included from OS
Instance Method Details
#color?(msg, code) ⇒ Boolean
19 20 21 |
# File 'lib/rubbr/cli.rb', line 19 def color?(msg, code) Rubbr.[:color] ? "#{code}#{msg}\e[0m" : msg end |
#disable_stderr ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rubbr/cli.rb', line 30 def disable_stderr old_stderr = STDERR.dup STDERR.reopen(null_file) yield STDERR.reopen(old_stderr) end |
#disable_stdinn ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rubbr/cli.rb', line 37 def disable_stdinn old_stdinn = STDIN.dup STDIN.reopen(null_file) yield STDIN.reopen(old_stdinn) end |
#disable_stdout ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rubbr/cli.rb', line 23 def disable_stdout old_stdout = STDOUT.dup STDOUT.reopen(null_file) yield STDOUT.reopen(old_stdout) end |
#error(message) ⇒ Object
15 16 17 |
# File 'lib/rubbr/cli.rb', line 15 def error() puts color?(" * #{}", "\e[31m") end |
#executable?(executable) ⇒ Boolean
44 45 46 47 48 49 |
# File 'lib/rubbr/cli.rb', line 44 def executable?(executable) disable_stdout do @existing = system("#{which_cmd} #{executable}") end @existing end |
#notice(message) ⇒ Object
7 8 9 |
# File 'lib/rubbr/cli.rb', line 7 def notice() puts color?(, "\e[32m") if Rubbr.[:verbose] end |
#valid_executable(executable) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/rubbr/cli.rb', line 51 def valid_executable(executable) if executable?(executable) executable else error "Missing executable #{executable}" exit end end |
#warning(message) ⇒ Object
11 12 13 |
# File 'lib/rubbr/cli.rb', line 11 def warning() puts color?(" - #{}", "\e[33m") if Rubbr.[:verbose] end |