Class: MCollective::Application::Completion

Inherits:
MCollective::Application show all
Defined in:
lib/mcollective/application/completion.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Instance Attribute Summary

Attributes inherited from MCollective::Application

#options

Instance Method Summary collapse

Methods inherited from MCollective::Application

[], []=, #application_cli_arguments, #application_description, #application_failure, application_options, #application_options, #application_parse_options, #application_usage, #clioptions, #configuration, description, #disconnect, exclude_argument_sections, external, external_help, #external_help, #external_main, #halt, #halt_code, #help, intialize_application_options, option, #rpcclient, #run, usage, #validate_cli_options, #validate_option

Methods included from RPC

const_missing, discovered, #empty_filter?, #printrpc, #printrpcstats, #rpcclient, #rpcoptions, stats

Instance Method Details

#list_actionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mcollective/application/completion.rb', line 55

def list_actions
  abort "Please specify an agent to list actions for" unless configuration[:agent]

  if options[:verbose]
    ddl = DDL.new(configuration[:agent], :agent)

    ddl.actions.sort.each do |action|
      puts "%s:%s" % [action, ddl.action_interface(action)[:description]]
    end
  else
    DDL.new(configuration[:agent], :agent).actions.sort.each {|a| puts a}
  end
rescue # rubocop:disable Lint/SuppressedException
end

#list_agentsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mcollective/application/completion.rb', line 41

def list_agents
  if options[:verbose]
    PluginManager.find(:agent, "ddl").each do |agent|
      begin
        ddl = DDL.new(agent)
        puts "%s:%s" % [agent, ddl.meta[:description]]
      rescue # rubocop:disable Lint/SuppressedException
      end
    end
  else
    PluginManager.find(:agent, "ddl").each {|p| puts p}
  end
end

#list_applicationsObject



85
86
87
88
89
90
91
92
93
# File 'lib/mcollective/application/completion.rb', line 85

def list_applications
  if options[:verbose]
    Applications.list.each do |app|
      puts "%s:%s" % [app, Applications[app].application_description]
    end
  else
    Applications.list.each {|a| puts a}
  end
end

#list_inputsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mcollective/application/completion.rb', line 70

def list_inputs
  abort "Please specify an action and agent to list inputs for" unless configuration[:agent] && configuration[:action]

  if options[:verbose]
    ddl = DDL.new(configuration[:agent], :agent)
    action = ddl.action_interface(configuration[:action])
    action[:input].keys.sort.each do |input|
      puts "%s:%s" % [input, action[:input][input][:description]]
    end
  else
    DDL.new(configuration[:agent], :agent).action_interface(configuration[:action])[:input].keys.sort.each {|i| puts i}
  end
rescue # rubocop:disable Lint/SuppressedException
end

#mainObject



95
96
97
98
99
100
101
102
# File 'lib/mcollective/application/completion.rb', line 95

def main
  actions = configuration.keys.map(&:to_s).grep(/^list_/)

  abort "Please choose either --list-[agents|actions|inputs|applications]" if actions.empty?
  abort "Please choose only one of --list-[agents|actions|inputs|applications]" if actions.size > 1

  send actions.first
end