Class: Eye::Cli

Inherits:
Thor show all
Includes:
Commands, Render, Server
Defined in:
lib/eye/cli.rb

Defined Under Namespace

Modules: Commands, Render, Server

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/eye/cli.rb', line 208

def self.exit_on_failure?
  true
end

Instance Method Details

#break(*masks) ⇒ Object



146
147
148
# File 'lib/eye/cli.rb', line 146

def break(*masks)
  send_command(:break_chain, *masks)
end

#check(conf) ⇒ Object



164
165
166
167
168
169
170
171
# File 'lib/eye/cli.rb', line 164

def check(conf)
  conf = File.expand_path(conf) if conf && !conf.empty?

  Eye::Local.host = options[:host] if options[:host]
  Eye::Dsl.verbose = options[:verbose]

  say_load_result Eye::Controller.new.check(conf), syntax: true
end

#explain(conf) ⇒ Object



176
177
178
179
180
181
182
183
# File 'lib/eye/cli.rb', line 176

def explain(conf)
  conf = File.expand_path(conf) if conf && !conf.empty?

  Eye::Local.host = options[:host] if options[:host]
  Eye::Dsl.verbose = options[:verbose]

  say_load_result Eye::Controller.new.explain(conf), print_config: true, syntax: true
end

#force_restart(*masks) ⇒ Object



135
136
137
138
# File 'lib/eye/cli.rb', line 135

def force_restart(*masks)
  send_command(:stop, *masks)
  send_command(:start, *masks)
end

#history(*masks) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/eye/cli.rb', line 73

def history(*masks)
  res = cmd(:history_data, *masks)
  if !masks.empty? && res && res.empty?
    error!('command :history, objects not found!')
  end
  if options[:json]
    say_json(res)
  else
    say render_history(res)
    say
  end
end

#info(mask = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eye/cli.rb', line 20

def info(mask = nil)
  h = {}
  h[:procline] = true if options[:procline]
  h[:debug] = true if options[:debug]

  res = cmd(:info_data, *Array(mask), h)
  if mask && res[:subtree] && res[:subtree].empty?
    error!('command :info, objects not found!')
  end

  if options[:json]
    say_json(res)
  else
    say render_info(res)
    say
  end
end

#load(*configs) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/eye/cli.rb', line 88

def load(*configs)
  configs.map! { |c| File.expand_path(c) }

  if options[:foreground]
    # in foreground we stop another server, and run just 1 current config version
    error!('foreground expected only one config') if configs.size > 1
    server_start_foreground(configs.first)

  elsif server_started?
    configs << Eye::Local.eyefile if Eye::Local.local_runner && configs.empty? && Eye::Local.eyefile
    say_load_result cmd(:load, *configs)

  else
    server_start(configs)

  end
end

#oinfo(mask = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/eye/cli.rb', line 61

def oinfo(mask = nil)
  res = cmd(:short_data, *Array(mask))
  if options[:json]
    say_json(res)
  else
    say render_info(res)
    say
  end
end

#quitObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/eye/cli.rb', line 109

def quit
  if options[:stop_all]
    Eye::Local.client_timeout = options[:timeout].to_i
    cmd(:stop_all, options[:timeout].to_i)
  end

  Eye::Local.client_timeout = Eye::Local.default_client_timeout
  res = _cmd(:quit)

  # if eye server got crazy, stop by force
  ensure_stop_previous_server if res != :corrupted_data

  # remove pid_file
  File.delete(Eye::Local.pid_path) if File.exist?(Eye::Local.pid_path)

  say "Eye quit ಠ╭╮ಠ (#{Eye::Local.home})", :yellow
end

#signal(sig, *masks) ⇒ Object



141
142
143
# File 'lib/eye/cli.rb', line 141

def signal(sig, *masks)
  send_command(:signal, sig, *masks)
end

#status(name) ⇒ Object



39
40
41
42
43
44
# File 'lib/eye/cli.rb', line 39

def status(name)
  res = cmd(:info_data, *Array(name))
  es, msg = render_status(res)
  say(msg, :red) if msg && !msg.empty?
  exit(es)
end

#trace(mask = '') ⇒ Object



151
152
153
# File 'lib/eye/cli.rb', line 151

def trace(mask = '')
  log_trace(mask)
end

#user_command(cmd, *args) ⇒ Object



204
205
206
# File 'lib/eye/cli.rb', line 204

def user_command(cmd, *args)
  send_command(:user_command, cmd, *args)
end

#versionObject



157
158
159
# File 'lib/eye/cli.rb', line 157

def version
  say Eye::ABOUT
end

#watch(*args) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/eye/cli.rb', line 187

def watch(*args)
  error!('You should install watch utility') if `which watch`.empty?

  cmd = if `watch --version 2>&1`.chop > '0.2.0'
    "watch -n 1 --color #{$0} i #{args * ' '}"
  else
    "watch -n 1 #{$0} i #{args * ' '}"
  end

  cmd += ' -p' if options[:procline]

  pid = Process.spawn(cmd)
  Process.waitpid(pid)
rescue Interrupt
end

#xinfoObject



49
50
51
52
53
54
55
56
57
# File 'lib/eye/cli.rb', line 49

def xinfo
  res = cmd(:debug_data, config: options[:config])
  if options[:json]
    say_json(res)
  else
    say render_debug_info(res)
    say
  end
end