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

Instance Method Details

#color?(msg, code) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rubbr/cli.rb', line 17

def color?(msg, code)
  Rubbr.options[:color] ? "#{code}#{msg}\e[0m" : msg
end

#disable_stderrObject



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_stdinnObject



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_stdoutObject



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(message)
  puts color?("  * #{message}", "\e[31m")
end

#executable?(executable) ⇒ Boolean

Returns:

  • (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(message)
  puts color?(message, "\e[32m") if Rubbr.options[: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(message)
  puts color?("  - #{message}", "\e[33m") if Rubbr.options[:verbose]
end