Class: Rspawn::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



17
18
19
20
21
# File 'lib/rspawn/cli.rb', line 17

def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  @class_options = config[:shell].base.options
  @config = get_config(args.first)
end

Instance Method Details

#restart(key) ⇒ Object



31
32
33
# File 'lib/rspawn/cli.rb', line 31

def restart(key)
  start_action(options['command'], 'restart')
end

#rm(key) ⇒ Object



58
59
60
# File 'lib/rspawn/cli.rb', line 58

def rm(key)
  @config.remove
end

#start(key) ⇒ Object



25
26
27
# File 'lib/rspawn/cli.rb', line 25

def start(key)
  start_action(options['command'], 'start')
end

#status(key = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rspawn/cli.rb', line 42

def status(key = nil)
  keys = key.nil? ? Dir.glob(@class_options['root'] + "/*") : [key]
  keys = keys.map { |file| File.basename(file) }
  result = {}
  keys.each do |proc_name|
    option, command = get_config(proc_name).option
    option[:status] = capture_stdout do
      RspawnWorker.spawn!(option, ["status"])
    end
    option[:command] = command
    result[proc_name] = option
  end
  puts JSON.pretty_generate(result)
end

#stop(key) ⇒ Object



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

def stop(key)
  option, command = @config.option
  RspawnWorker.spawn!(option, ["stop"])
end

#tail(key) ⇒ Object



63
64
65
66
# File 'lib/rspawn/cli.rb', line 63

def tail(key)
  option, command = @config.option(nil)
  tail_log(option[:log_file])
end

#versionObject



69
70
71
# File 'lib/rspawn/cli.rb', line 69

def version
  puts VERSION
end