Class: Tastevin::CLI
- Inherits:
-
Thor
- Object
- Thor
- Tastevin::CLI
- Defined in:
- lib/tastevin/cli.rb
Instance Method Summary collapse
- #add(agent, host, port) ⇒ Object
- #get(agent, key) ⇒ Object
- #ls ⇒ Object
- #rm(agent) ⇒ Object
- #set(agent, key, value) ⇒ Object
- #usage ⇒ Object
Instance Method Details
#add(agent, host, port) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tastevin/cli.rb', line 46 def ls config = Config.load config.list.each do |name| if [: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) ⇒ Object
36 37 38 39 40 41 42 |
# 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) ⇒ Object
70 71 72 73 74 75 76 77 |
# 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 ⇒ Object
13 14 15 16 17 18 19 20 |
# 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 |