Class: Smith::Commands::List

Inherits:
Smith::CommandBase show all
Includes:
Common
Defined in:
lib/smith/commands/agency/list.rb

Instance Attribute Summary

Attributes inherited from Smith::CommandBase

#options, #target

Instance Method Summary collapse

Methods included from Common

#agent_group

Methods inherited from Smith::CommandBase

#banner, #format_help, #initialize, #parse_options

Methods included from Logger

included

Constructor Details

This class inherits a constructor from Smith::CommandBase

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/smith/commands/agency/list.rb', line 11

def execute
  case
  when target.size > 0
    selected_agents = agents.find_by_name(target)
  when options[:group] && options[:all]
    selected_agents = agent_group(options[:group]).map do |agent_name|
      a = agents.find_by_name(agent_name)
      (a.empty?) ? AgentProcess.new(nil, :name => agent_name, :uuid => nil_uuid) : a.first
    end
  when options[:group]
    begin
      selected_agents = agents.find_by_name(agent_group(options[:group]))
    rescue RuntimeError => e
      responder.fail(e.message)
      return
    end
  else
    selected_agents = (options[:all]) ? agents.to_a : agents.state(:running)
  end

  responder.succeed((selected_agents.empty?) ? '' : format(selected_agents, options[:long]))
end