class Eye::Cli
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/eye/cli.rb, line 208 def self.exit_on_failure? true end
Public Instance Methods
break(*masks)
click to toggle source
# File lib/eye/cli.rb, line 146 def break(*masks) send_command(:break_chain, *masks) end
check(conf)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/eye/cli.rb, line 135 def force_restart(*masks) send_command(:stop, *masks) send_command(:start, *masks) end
history(*masks)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
quit()
click to toggle source
# 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)
click to toggle source
# File lib/eye/cli.rb, line 141 def signal(sig, *masks) send_command(:signal, sig, *masks) end
status(name)
click to toggle source
# 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 = '')
click to toggle source
# File lib/eye/cli.rb, line 151 def trace(mask = '') log_trace(mask) end
user_command(cmd, *args)
click to toggle source
# File lib/eye/cli.rb, line 204 def user_command(cmd, *args) send_command(:user_command, cmd, *args) end
version()
click to toggle source
# File lib/eye/cli.rb, line 157 def version say Eye::ABOUT end
watch(*args)
click to toggle source
# 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
xinfo()
click to toggle source
# 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
Private Instance Methods
error!(msg)
click to toggle source
# File lib/eye/cli.rb, line 214 def error!(msg) say msg, :red exit 1 end
log_trace(tag = '')
click to toggle source
# File lib/eye/cli.rb, line 224 def log_trace(tag = '') log_file = cmd(:logger_dev) if log_file && File.exist?(log_file) Process.exec "tail -n 100 -f #{log_file} | grep '#{tag}'" else error! "log file not found #{log_file.inspect}" end end
print(msg, new_line = true)
click to toggle source
# File lib/eye/cli.rb, line 219 def print(msg, new_line = true) say msg if msg && !msg.empty? say if new_line end
say_json(obj)
click to toggle source
# File lib/eye/cli.rb, line 233 def say_json(obj) require 'json' say JSON.dump(obj) end