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

Methods included from OS

#os

Instance Method Details

#color?(msg, code) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rubbr/cli.rb', line 19

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

#disable_stderrObject



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_stdinnObject



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_stdoutObject



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

#executable?(executable) ⇒ Boolean

Returns:

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