Module: Busser::UI

Included in:
Thor::Base, Thor::BaseGroup
Defined in:
lib/busser/ui.rb

Overview

User interface methods.

Author:

Class Method Summary collapse

Class Method Details



31
32
33
# File 'lib/busser/ui.rb', line 31

def banner(msg)
  say("-----> #{msg}")
end

.die(msg, exitstatus = 1) ⇒ Object



63
64
65
66
# File 'lib/busser/ui.rb', line 63

def die(msg, exitstatus = 1)
  fatal(msg)
  exit(exitstatus)
end

.fatal(msg) ⇒ Object



43
44
45
# File 'lib/busser/ui.rb', line 43

def fatal(msg)
  error("!!!!!! #{msg}")
end

.handle_command(type, cmd) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/busser/ui.rb', line 72

def handle_command(type, cmd)
  begin
    yield
  rescue => e
    fatal(
      "#{type} [#{cmd}] raised an exception: #{e.message}\n" +
      e.backtrace.join("\n"))
    raise
  end

  if status.nil?
    die(
      "#{type} [#{cmd}] did not return a valid status. " \
      "This instance could be starved for RAM or may have swap disabled."
    )
  elsif status.success?
    true
  else
    code = status.exitstatus
    die("#{type} [#{cmd}] exit code was #{code}", code)
  end
end

.info(msg) ⇒ Object



35
36
37
# File 'lib/busser/ui.rb', line 35

def info(msg)
  say("       #{msg}")
end

.run!(cmd, config = {}) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/busser/ui.rb', line 47

def run!(cmd, config = {})
  config = { :capture => false, :verbose => false }.merge(config)

  handle_command("Command", cmd) do
    run(cmd, config)
  end
end

.run_ruby_script!(cmd, config = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/busser/ui.rb', line 55

def run_ruby_script!(cmd, config = {})
  config = { :capture => false, :verbose => false }.merge(config)

  handle_command("Ruby Script", cmd) do
    run_ruby_script(cmd, config)
  end
end

.statusObject



68
69
70
# File 'lib/busser/ui.rb', line 68

def status
  $?
end

.warn(msg) ⇒ Object



39
40
41
# File 'lib/busser/ui.rb', line 39

def warn(msg)
  say(">>>>>> #{msg}")
end