Class: Explorer::CLI::Process

Inherits:
Thor
  • Object
show all
Defined in:
lib/explorer/cli/process.rb

Instance Method Summary collapse

Instance Method Details

#add(label, cmd) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/explorer/cli/process.rb', line 19

def add(label, cmd)
  Celluloid.logger = nil # Silence celluloid

  ipc = IPCClient.new
  ipc.cmd_add(label, cmd, options[:dir])
  puts Rainbow("Added #{label}").color(:green).bright
rescue Errno::ENOENT
  puts Rainbow('Explore is not running').color(:red).bright
end

#listObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/explorer/cli/process.rb', line 63

def list
  Celluloid.logger = nil # Silence celluloid

  ipc = IPCClient.new
  list = ipc.cmd_list
  data = list.map do |p|
    color = if p['state'] == 'stopped'
              'red'
            else
              'green'
            end
    {
      label: "[#{color}]#{p['label']}[/]",
      command: "[#{color}]#{p['cmd']}[/]",
      'working directory' => "[#{color}]#{p['dir']}[/]",
      'PID' => "[#{color}]#{p['pid']}[/]",
      'exit code' => "[#{color}]#{p['status']}[/]",
      'status' => "[#{color}]#{p['state']}[/]",
    }
  end
  Formatador.display_compact_table(data, [:label, :command, 'PID', 'exit code', 'status', 'working directory'])
rescue Errno::ENOENT
  puts Rainbow('Explore is not running').color(:red).bright
end

#remove(label) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/explorer/cli/process.rb', line 52

def remove(label)
  Celluloid.logger = nil # Silence celluloid

  ipc = IPCClient.new
  ipc.cmd_remove(label)
  puts Rainbow("Removed #{label}").color(:green).bright
rescue Errno::ENOENT
  puts Rainbow('Explore is not running').color(:red).bright
end

#start(label) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/explorer/cli/process.rb', line 30

def start(label)
  Celluloid.logger = nil # Silence celluloid

  ipc = IPCClient.new
  ipc.cmd_start(label)
  puts Rainbow("Started #{label}").color(:green).bright
rescue Errno::ENOENT
  puts Rainbow('Explore is not running').color(:red).bright
end

#stop(label) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/explorer/cli/process.rb', line 41

def stop(label)
  Celluloid.logger = nil # Silence celluloid

  ipc = IPCClient.new
  ipc.cmd_stop(label)
  puts Rainbow("Stopped #{label}").color(:green).bright
rescue Errno::ENOENT
  puts Rainbow('Explore is not running').color(:red).bright
end

#tailObject



8
9
10
11
12
13
14
15
# File 'lib/explorer/cli/process.rb', line 8

def tail
  Celluloid.logger = nil # Silence celluloid

  ipc = IPCClient.new
  ipc.tail
rescue Errno::ENOENT
  puts Rainbow('Explore is not running').color(:red).bright
end