Module: PuppetDebugger::Support::InputResponders
- Included in:
- PuppetDebugger::Support
- Defined in:
- lib/puppet-debugger/support/input_responders.rb
Instance Method Summary collapse
- #classes(_args = []) ⇒ Object
- #classification(_args = []) ⇒ Object
- #environment(_args = []) ⇒ Object
-
#facterdb_filter(_args = []) ⇒ Object
displays the facterdb filter.
- #facts(_args = []) ⇒ Object
- #functions(args = []) ⇒ Object
- #handle_set(input) ⇒ Object
- #help(_args = []) ⇒ Object
- #krt(_args = []) ⇒ Object
- #play(args = []) ⇒ Object
- #reset(_args = []) ⇒ Object
- #resources(args = []) ⇒ Object
- #set_log_level(level) ⇒ Object
- #static_responder_list ⇒ Object
- #vars(_args = []) ⇒ Object
-
#whereami(_command = nil, _args = nil) ⇒ String
method to show the surrounding code.
Instance Method Details
#classes(_args = []) ⇒ Object
130 131 132 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 130 def classes(_args = []) scope.compiler.catalog.classes.ai end |
#classification(_args = []) ⇒ Object
114 115 116 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 114 def classification(_args = []) node.classes.ai end |
#environment(_args = []) ⇒ Object
78 79 80 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 78 def environment(_args = []) "Puppet Environment: #{puppet_env_name}" end |
#facterdb_filter(_args = []) ⇒ Object
displays the facterdb filter
29 30 31 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 29 def facterdb_filter(_args = []) dynamic_facterdb_filter.ai end |
#facts(_args = []) ⇒ Object
60 61 62 63 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 60 def facts(_args = []) variables = node.facts.values variables.ai(sort_keys: true, indent: -1) end |
#functions(args = []) ⇒ Object
65 66 67 68 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 65 def functions(args = []) filter = args.first || '' function_map.keys.sort.grep(/^#{Regexp.escape(filter)}/) end |
#handle_set(input) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 37 def handle_set(input) output = '' args = input.split(' ') args.shift # throw away the set case args.shift when /node/ if name = args.shift output = "Resetting to use node #{name}" reset set_remote_node_name(name) else out_buffer.puts 'Must supply a valid node name' end when /loglevel/ if level = args.shift @log_level = level set_log_level(level) output = "loglevel #{Puppet::Util::Log.level} is set" end end output end |
#help(_args = []) ⇒ Object
33 34 35 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 33 def help(_args = []) PuppetDebugger::Cli.print_repl_desc end |
#krt(_args = []) ⇒ Object
103 104 105 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 103 def krt(_args = []) known_resource_types.ai(sort_keys: true, indent: -1) end |
#play(args = []) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 107 def play(args = []) config = {} config[:play] = args.first play_back(config) nil # we don't want to return anything end |
#reset(_args = []) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 82 def reset(_args = []) set_scope(nil) set_remote_node_name(nil) set_node(nil) set_facts(nil) set_environment(nil) set_compiler(nil) set_log_level(log_level) end |
#resources(args = []) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 118 def resources(args = []) res = scope.compiler.catalog.resources.map do |res| res.to_s.gsub(/\[/, "['").gsub(/\]/, "']") # ensure the title has quotes end if !args.first.nil? res[args.first.to_i].ai else output = "Resources not shown in any specific order\n".warning output += res.ai end end |
#set_log_level(level) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 92 def set_log_level(level) Puppet::Util::Log.level = level.to_sym buffer_log = Puppet::Util::Log.newdestination(:buffer) if buffer_log # if this is already set the buffer_log is nil buffer_log.out_buffer = out_buffer buffer_log.err_buffer = out_buffer end nil end |
#static_responder_list ⇒ Object
5 6 7 8 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 5 def static_responder_list %w(exit functions classification vars facterdb_filter krt facts resources classes whereami play reset help) end |
#vars(_args = []) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 70 def vars(_args = []) # remove duplicate variables that are also in the facts hash variables = scope.to_hash.delete_if { |key, _value| node.facts.values.key?(key) } variables['facts'] = 'removed by the puppet-debugger' if variables.key?('facts') output = 'Facts were removed for easier viewing'.ai + "\n" output += variables.ai(sort_keys: true, indent: -1) end |
#whereami(_command = nil, _args = nil) ⇒ String
method to show the surrounding code
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet-debugger/support/input_responders.rb', line 13 def whereami(_command = nil, _args = nil) file = @source_file line_num = @source_line_num if file && line_num if file == :code source_code = Puppet[:code] code = DebuggerCode.from_string(source_code, :puppet) else code = DebuggerCode.from_file(file, :puppet) end return code.with_marker(line_num).around(line_num, 5).with_line_numbers.with_indentation(5).with_file_reference.to_s end end |