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].freeze
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



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

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

.command_list_regexObject



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

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

.command_outputObject



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

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
74
# File 'lib/plugins/puppet-debugger/input_responders/commands.rb', line 69

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

  plug
end

.pluginsObject



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

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

Instance Method Details

#command_groupsObject



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

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



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

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



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

def run(_args = [])
  commands_list
end