Class: PuppetDebugger::InputResponders::Commands

Inherits:
PuppetDebugger::InputResponderPlugin show all
Defined in:
lib/plugins/puppet-debugger/input_responders/commands.rb

Constant Summary collapse

COMMAND_WORDS =
%w(commands)
SUMMARY =
'List all available commands, aka. this screen'
COMMAND_GROUP =
:help

Instance Attribute Summary

Attributes inherited from PuppetDebugger::InputResponderPlugin

#debugger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PuppetDebugger::InputResponderPlugin

command_completion, command_group, command_words, details, execute, #modules_paths, #puppet_debugger_lib_dir, summary

Class Method Details

.command_listObject



50
51
52
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 50

def self.command_list
  command_output.map{|f| f[:words] }.flatten
end

.command_list_regexObject



45
46
47
48
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 45

def self.command_list_regex
  out = command_list.map {|n| "^#{n}"}.join('|')
  %r(#{out})
end

.command_outputObject



54
55
56
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 54

def self.command_output
  plugins.map(&:details)
end

.plugin_from_command(name) ⇒ PuppetDebugger::InputResponders::InputResponderPlugin

Parameters:

  • name (String)
    • the name of the command that is associated with a plugin

Returns:

  • (PuppetDebugger::InputResponders::InputResponderPlugin)

Raises:



69
70
71
72
73
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 69

def self.plugin_from_command(name)
  p = plugins.find {|p| p::COMMAND_WORDS.include?(name)}
  raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{name}") unless p
  p
end

.pluginsObject



58
59
60
61
62
63
64
65
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 58

def self.plugins
  begin
    debug_plugins = Pluginator.find('puppet-debugger')
    debug_plugins["input_responders"]
  rescue NoMethodError => e
    raise PuppetDebugger::Exception::InvalidCommand.new(message: "Unsupported gem version.  Please update with: gem update --system")
  end
end

Instance Method Details

#command_groupsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 31

def command_groups
  unless @command_groups
    @command_groups = {}
    self.class.command_output.each do | item|
      if @command_groups[item[:group]]
        @command_groups[item[:group]].merge!({ item[:words].first => item[:summary] })
      else
        @command_groups[item[:group]] = { item[:words].first => item[:summary] }
      end
    end
  end
  @command_groups
end

#commands_listObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 13

def commands_list
  unless @commands_list
    @commands_list = ''
    command_groups.sort.each do |command_group|
      group_name = command_group[0].to_s.capitalize.bold
      commands = command_group[1]
      @commands_list += ' ' + group_name + "\n"
      commands.sort.each do |command|
        command_name = command[0]
        command_description = command[1]
        @commands_list += format("   %-20s %s\n", command_name, command_description)
      end
      @commands_list += "\n"
    end
  end
  @commands_list
end

#run(args = []) ⇒ Object



9
10
11
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 9

def run(args = [])
  commands_list
end