class Tastevin::CLI
Public Instance Methods
add(agent, host, port)
click to toggle source
# File lib/tastevin/cli.rb, line 23 def add(agent, host, port) highline = HighLine.new username = highline.ask("Username: ") password = highline.ask("Password: ") { |q| q.echo = '*' } config = Config.load config.add(agent, host, port, username, password) config.save end
get(agent, key)
click to toggle source
# File lib/tastevin/cli.rb, line 80 def get(agent, key) config = Config.load check_agent_exists(agent, config) communicate(agent) do value = Agent.get(config[agent], key) if value.length > 0 puts value else error("No such key '#{key}' in agent '#{agent}'") end end end
ls()
click to toggle source
# File lib/tastevin/cli.rb, line 46 def ls config = Config.load config.list.each do |name| if options[:status] username = config[name]['username'] host = config[name]['host'] port = config[name]['port'] text = "%-10s %s@%s:%s" % [name, username, host, port ] status = Agent.status(config[name]) if status == :offline puts "#{text} (#{'offline'.color(:red)})" else puts text end else puts name end end end
rm(agent)
click to toggle source
# File lib/tastevin/cli.rb, line 36 def rm(agent) config = Config.load check_agent_exists(agent, config) config.remove(agent) config.save end
set(agent, key, value)
click to toggle source
# File lib/tastevin/cli.rb, line 70 def set(agent, key, value) config = Config.load check_agent_exists(agent, config) communicate(agent) do Agent.set(config[agent], key, value) end end
usage()
click to toggle source
# File lib/tastevin/cli.rb, line 13 def usage puts <<-EOF Tastevin is a command line utility for configuring and monitoring agents. EOF help end
Private Instance Methods
check_agent_exists(agent, config)
click to toggle source
# File lib/tastevin/cli.rb, line 108 def check_agent_exists(agent, config) error("No such agent '#{agent}'") unless config.exists? agent end
communicate(agent, &block)
click to toggle source
# File lib/tastevin/cli.rb, line 96 def communicate(agent, &block) begin block.call rescue ConnectionError error("Connection to agent '#{agent}' failed") rescue LoginError error("Logging into agent '#{agent}' failed") rescue Error => e error("Operation failed: #{e}") end end
error(message)
click to toggle source
# File lib/tastevin/cli.rb, line 112 def error(message) abort "tastevin: error: #{message}" end