Class: Titan::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/titan/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



7
8
9
10
# File 'lib/titan/cli.rb', line 7

def initialize(*)
  super
  @shell = Thor::Shell::Basic.new
end

Instance Method Details

#helpObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/titan/cli.rb', line 13

def help
  @shell.say "The following methods are available through typing `titan method_name`"
  @shell.say ""
  available_methods = [
    ["method_name", "description"],
    ["", ""],
    ["help",        "Prints this page and describes available methods"],
    ["status",      "Prints the status of all threads managed by Titan"],
    ["version",     "Prints the currently installed version"]
  ]
  @shell.print_table(available_methods)
end

#statusObject



27
28
29
30
31
32
33
# File 'lib/titan/cli.rb', line 27

def status
  table_header = ["id", "pid", "status"]
  threads = Titan::Thread.all.each_value.collect do |thread|
    [thread.id.to_s, thread.pid.to_s, thread.alive? ? "alive" : "dead"]
  end
  @shell.print_table(threads.unshift(table_header)) unless threads.empty?
end

#versionObject



36
37
38
# File 'lib/titan/cli.rb', line 36

def version
  @shell.say Titan::VERSION
end