puppet-debugger 0.17.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +12 -26
  3. data/.rubocop.yml +64 -232
  4. data/.rubocop_todo.yml +89 -147
  5. data/.vscode/launch.json +15 -0
  6. data/CHANGELOG.md +29 -0
  7. data/Gemfile +9 -6
  8. data/README.md +27 -14
  9. data/Rakefile +11 -12
  10. data/bin/pdb +1 -1
  11. data/lib/awesome_print/ext/awesome_puppet.rb +10 -8
  12. data/lib/plugins/puppet-debugger/input_responders/benchmark.rb +5 -4
  13. data/lib/plugins/puppet-debugger/input_responders/classes.rb +14 -2
  14. data/lib/plugins/puppet-debugger/input_responders/classification.rb +4 -2
  15. data/lib/plugins/puppet-debugger/input_responders/commands.rb +18 -18
  16. data/lib/plugins/puppet-debugger/input_responders/datatypes.rb +22 -6
  17. data/lib/plugins/puppet-debugger/input_responders/environment.rb +4 -2
  18. data/lib/plugins/puppet-debugger/input_responders/exit.rb +5 -3
  19. data/lib/plugins/puppet-debugger/input_responders/facterdb_filter.rb +4 -2
  20. data/lib/plugins/puppet-debugger/input_responders/facts.rb +4 -2
  21. data/lib/plugins/puppet-debugger/input_responders/functions.rb +34 -32
  22. data/lib/plugins/puppet-debugger/input_responders/help.rb +4 -2
  23. data/lib/plugins/puppet-debugger/input_responders/krt.rb +4 -2
  24. data/lib/plugins/puppet-debugger/input_responders/play.rb +22 -24
  25. data/lib/plugins/puppet-debugger/input_responders/reset.rb +5 -3
  26. data/lib/plugins/puppet-debugger/input_responders/resources.rb +16 -7
  27. data/lib/plugins/puppet-debugger/input_responders/set.rb +34 -32
  28. data/lib/plugins/puppet-debugger/input_responders/stacktrace.rb +31 -0
  29. data/lib/plugins/puppet-debugger/input_responders/types.rb +6 -2
  30. data/lib/plugins/puppet-debugger/input_responders/vars.rb +8 -7
  31. data/lib/plugins/puppet-debugger/input_responders/whereami.rb +5 -3
  32. data/lib/puppet-debugger/cli.rb +129 -91
  33. data/lib/puppet-debugger/code/code_file.rb +13 -14
  34. data/lib/puppet-debugger/code/code_range.rb +5 -3
  35. data/lib/puppet-debugger/code/loc.rb +1 -1
  36. data/lib/puppet-debugger/debugger_code.rb +2 -0
  37. data/lib/puppet-debugger/hooks.rb +15 -16
  38. data/lib/puppet-debugger/input_responder_plugin.rb +54 -52
  39. data/lib/puppet-debugger/monkey_patches.rb +4 -1
  40. data/lib/puppet-debugger/plugin_test_helper.rb +9 -8
  41. data/lib/puppet-debugger/support.rb +44 -18
  42. data/lib/puppet-debugger/support/environment.rb +6 -5
  43. data/lib/puppet-debugger/support/errors.rb +25 -27
  44. data/lib/puppet-debugger/support/facts.rb +5 -5
  45. data/lib/puppet-debugger/support/node.rb +4 -7
  46. data/lib/puppet-debugger/support/scope.rb +29 -0
  47. data/lib/puppet-debugger/trollop.rb +38 -31
  48. data/lib/puppet-debugger/version.rb +1 -1
  49. data/lib/puppet/application/debugger.rb +151 -126
  50. data/output.json +1 -0
  51. data/puppet-debugger.gemspec +18 -15
  52. data/spec/awesome_print/ext/awesome_puppet_spec.rb +30 -30
  53. data/spec/fixtures/pe-xl-core-0.puppet.vm.json +1 -0
  54. data/spec/fixtures/sample_start_debugger.pp +3 -2
  55. data/spec/hooks_spec.rb +33 -35
  56. data/spec/input_responder_plugin_spec.rb +7 -6
  57. data/spec/input_responders/benchmark_spec.rb +3 -1
  58. data/spec/input_responders/classes_spec.rb +12 -13
  59. data/spec/input_responders/classification_spec.rb +4 -2
  60. data/spec/input_responders/commands_spec.rb +2 -0
  61. data/spec/input_responders/datatypes_spec.rb +8 -2
  62. data/spec/input_responders/environment_spec.rb +2 -0
  63. data/spec/input_responders/exit_spec.rb +9 -11
  64. data/spec/input_responders/facterdb_filter_spec.rb +2 -0
  65. data/spec/input_responders/facts_spec.rb +2 -0
  66. data/spec/input_responders/functions_spec.rb +30 -28
  67. data/spec/input_responders/help_spec.rb +5 -3
  68. data/spec/input_responders/krt_spec.rb +3 -1
  69. data/spec/input_responders/play_spec.rb +10 -20
  70. data/spec/input_responders/reset_spec.rb +2 -0
  71. data/spec/input_responders/resources_spec.rb +7 -1
  72. data/spec/input_responders/set_spec.rb +3 -1
  73. data/spec/input_responders/stacktrace_spec.rb +15 -0
  74. data/spec/input_responders/types_spec.rb +2 -0
  75. data/spec/input_responders/vars_spec.rb +4 -4
  76. data/spec/input_responders/whereami_spec.rb +2 -0
  77. data/spec/pdb_spec.rb +0 -9
  78. data/spec/puppet/application/debugger_spec.rb +35 -17
  79. data/spec/puppet_debugger_spec.rb +81 -84
  80. data/spec/remote_node_spec.rb +1 -5
  81. data/spec/spec_helper.rb +22 -18
  82. data/spec/support_spec.rb +3 -5
  83. data/test_matrix.rb +1 -1
  84. metadata +54 -21
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Exit < InputResponderPlugin
5
- COMMAND_WORDS = %w(exit)
6
- SUMMARY = 'Quit Puppet Debugger.'
7
+ COMMAND_WORDS = %w[exit].freeze
8
+ SUMMARY = 'Quit Puppet Debugger, or use control-d'
7
9
  COMMAND_GROUP = :help
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  exit 0
11
13
  end
12
14
  end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class FacterdbFilter < InputResponderPlugin
5
- COMMAND_WORDS = %w(facterdb_filter ff)
7
+ COMMAND_WORDS = %w[facterdb_filter ff].freeze
6
8
  SUMMARY = 'Set the facterdb filter'
7
9
  COMMAND_GROUP = :node
8
10
 
9
11
  # displays the facterdb filter
10
12
  # @param [Array] - args is not used
11
- def run(args = [])
13
+ def run(_args = [])
12
14
  debugger.dynamic_facterdb_filter.ai
13
15
  end
14
16
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Facts < InputResponderPlugin
5
- COMMAND_WORDS = %w(facts)
7
+ COMMAND_WORDS = %w[facts].freeze
6
8
  SUMMARY = 'List all the facts associated with the node.'
7
9
  COMMAND_GROUP = :node
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  variables = debugger.node.facts.values
11
13
  variables.ai(sort_keys: true, indent: -1)
12
14
  end
@@ -1,23 +1,25 @@
1
- require "puppet-debugger/input_responder_plugin"
2
- require "table_print"
1
+ # frozen_string_literal: true
2
+
3
+ require 'puppet-debugger/input_responder_plugin'
4
+ require 'table_print'
3
5
  require 'fileutils'
4
6
  require 'bundler'
5
7
 
6
8
  module PuppetDebugger
7
9
  module InputResponders
8
10
  class Functions < InputResponderPlugin
9
- COMMAND_WORDS = %w(functions)
10
- SUMMARY = "List all the functions available in the environment."
11
+ COMMAND_WORDS = %w[functions].freeze
12
+ SUMMARY = 'List all the functions available in the environment.'
11
13
  COMMAND_GROUP = :environment
12
- FUNC_NATIVE_NAME_REGEX = %r{\Afunction\s([\w\:]+)}
13
- FUNC_V4_NAME_REGEX = %r{Puppet\:\:Functions.create_function\s?\(?\:?\'?([\w\:]+)}
14
+ FUNC_NATIVE_NAME_REGEX = /\Afunction\s([\w\:]+)/.freeze
15
+ FUNC_V4_NAME_REGEX = /Puppet\:\:Functions.create_function\s?\(?\:?\'?([\w\:]+)/.freeze
14
16
 
15
17
  def run(args = [])
16
- filter = args.first || ""
17
- TablePrint::Printer.table_print(sorted_list(filter), [:full_name, :mod_name])
18
+ filter = args.first || ''
19
+ TablePrint::Printer.table_print(sorted_list(filter), %i[full_name mod_name])
18
20
  end
19
21
 
20
- def sorted_list(filter = "")
22
+ def sorted_list(filter = '')
21
23
  search = /#{Regexp.escape(filter)}/
22
24
  function_map.values.find_all do |v|
23
25
  "#{v[:mod_name]}_#{v[:full_name]}" =~ search
@@ -27,7 +29,7 @@ module PuppetDebugger
27
29
  # append a () to functions so we know they are functions
28
30
  def func_list
29
31
  # ideally we should get a list of function names via the puppet loader
30
- function_map.map { |name, metadata| "#{metadata[:full_name]}()" }
32
+ function_map.map { |_name, metadata| "#{metadata[:full_name]}()" }
31
33
  end
32
34
 
33
35
  # @return [Hash] - a map of all the functions
@@ -45,8 +47,8 @@ module PuppetDebugger
45
47
  def current_module_dir
46
48
  @current_module_dir ||= begin
47
49
  File.dirname(::Bundler.default_gemfile)
48
- rescue ::Bundler::GemfileNotFound
49
- Dir.pwd
50
+ rescue ::Bundler::GemfileNotFound
51
+ Dir.pwd
50
52
  end
51
53
  end
52
54
 
@@ -62,26 +64,26 @@ module PuppetDebugger
62
64
  namespace = nil
63
65
  name = nil
64
66
  if file =~ /\.pp/
65
- File.readlines(file, :encoding => "UTF-8").find do |line|
67
+ File.readlines(file, encoding: 'UTF-8').find do |line|
66
68
  # TODO: not getting namespace for functio
67
- if line.match(FUNC_NATIVE_NAME_REGEX)
68
- namespace, name = $1.split("::", 2)
69
- name = namespace if name.nil?
70
- namespace = "" if namespace == name
71
- end
69
+ next unless line.match(FUNC_NATIVE_NAME_REGEX)
70
+
71
+ namespace, name = Regexp.last_match(1).split('::', 2)
72
+ name = namespace if name.nil?
73
+ namespace = '' if namespace == name
72
74
  end
73
- elsif file.include?("lib/puppet/functions")
74
- File.readlines(file, :encoding => "UTF-8").find do |line|
75
- if line.match(FUNC_V4_NAME_REGEX)
76
- namespace, name = $1.split("::", 2)
77
- name = namespace if name.nil?
78
- namespace = "" if namespace == name
79
- end
75
+ elsif file.include?('lib/puppet/functions')
76
+ File.readlines(file, encoding: 'UTF-8').find do |line|
77
+ next unless line.match(FUNC_V4_NAME_REGEX)
78
+
79
+ namespace, name = Regexp.last_match(1).split('::', 2)
80
+ name = namespace if name.nil?
81
+ namespace = '' if namespace == name
80
82
  end
81
83
  end
82
84
  name ||= File.basename(file, File.extname(file))
83
85
  match = file.match('\/(?<mod>[\w\-\.]+)\/(lib|functions|manifests)')
84
- summary_match = File.read(file, :encoding => "UTF-8").match(/@summary\s(.*)/)
86
+ summary_match = File.read(file, encoding: 'UTF-8').match(/@summary\s(.*)/)
85
87
  summary = summary_match[1] if summary_match
86
88
  # fetch the puppet version if this is a function from puppet gem
87
89
  captures = file.match(/(puppet-[\d\.]+)/)
@@ -106,15 +108,15 @@ module PuppetDebugger
106
108
  # in the future we may want to utilize the puppet loaders to find these things
107
109
  def function_files
108
110
  search_dirs = lib_dirs.map do |lib_dir|
109
- [File.join(lib_dir, "puppet", "functions", "**", "*.rb"),
110
- File.join(lib_dir, "functions", "**", "*.rb"),
111
- File.join(File.dirname(lib_dir), "functions", "**", "*.pp"),
112
- File.join(lib_dir, "puppet", "parser", "functions", "*.rb")]
111
+ [File.join(lib_dir, 'puppet', 'functions', '**', '*.rb'),
112
+ File.join(lib_dir, 'functions', '**', '*.rb'),
113
+ File.join(File.dirname(lib_dir), 'functions', '**', '*.pp'),
114
+ File.join(lib_dir, 'puppet', 'parser', 'functions', '*.rb')]
113
115
  end
114
116
 
115
117
  # add puppet lib directories
116
- search_dirs << [File.join(puppet_lib_dir, "puppet", "functions", "**", "*.rb"),
117
- File.join(puppet_lib_dir, "puppet", "parser", "functions", "*.rb")]
118
+ search_dirs << [File.join(puppet_lib_dir, 'puppet', 'functions', '**', '*.rb'),
119
+ File.join(puppet_lib_dir, 'puppet', 'parser', 'functions', '*.rb')]
118
120
  Dir.glob(search_dirs.flatten)
119
121
  end
120
122
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Help < InputResponderPlugin
5
- COMMAND_WORDS = %w(help)
7
+ COMMAND_WORDS = %w[help].freeze
6
8
  SUMMARY = 'Show the help screen with version information.'
7
9
  COMMAND_GROUP = :help
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  PuppetDebugger::Cli.print_repl_desc
11
13
  end
12
14
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Krt < InputResponderPlugin
5
- COMMAND_WORDS = %w(krt)
7
+ COMMAND_WORDS = %w[krt].freeze
6
8
  SUMMARY = 'List all the known resource types.'
7
9
  COMMAND_GROUP = :scope
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  debugger.known_resource_types.ai(sort_keys: true, indent: -1)
11
13
  end
12
14
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Play < InputResponderPlugin
5
- COMMAND_WORDS = %w(play)
7
+ COMMAND_WORDS = %w[play].freeze
6
8
  SUMMARY = 'Playback a file or URL as input.'
7
9
  COMMAND_GROUP = :editing
8
10
 
@@ -20,7 +22,7 @@ module PuppetDebugger
20
22
  elsif File.exist? config[:play]
21
23
  play_back_string(File.read(config[:play]))
22
24
  else config[:play]
23
- debugger.out_buffer.puts "puppet-debugger can't play #{config[:play]}'"
25
+ debugger.out_buffer.puts "puppet-debugger can't play #{config[:play]}'"
24
26
  end
25
27
  end
26
28
  end
@@ -29,29 +31,29 @@ module PuppetDebugger
29
31
  require 'uri'
30
32
  url_data = URI(url)
31
33
  case url_data.host
32
- when /^gist\.github*/
33
- url = url += '.txt' unless url_data.path =~ /raw/
34
- url
35
- when /^github.com/
36
- url.gsub('blob', 'raw') if url_data.path =~ /blob/
37
- when /^gist.github.com/
38
- url = url += '.txt' unless url_data.path =~ /raw/
34
+ when /^gist\.github*/
35
+ url = url += '.txt' unless url_data.path =~ /raw/
36
+ url
37
+ when /^github.com/
38
+ url.gsub('blob', 'raw') if url_data.path =~ /blob/
39
+ when /^gist.github.com/
40
+ url = url += '.txt' unless url_data.path =~ /raw/
41
+ url
42
+ when /^gitlab.com/
43
+ if url_data.path =~ /snippets/
44
+ url += '/raw' unless url_data.path =~ /raw/
39
45
  url
40
- when /^gitlab.com/
41
- if url_data.path =~ /snippets/
42
- url += '/raw' unless url_data.path =~ /raw/
43
- url
44
- else
45
- url.gsub('blob', 'raw')
46
- end
47
46
  else
48
- url
47
+ url.gsub('blob', 'raw')
48
+ end
49
+ else
50
+ url
49
51
  end
50
52
  end
51
53
 
52
54
  # opens the url and reads the data
53
55
  def fetch_url_data(url)
54
- open(url).read
56
+ URI.open(url).read # open(url).read
55
57
  end
56
58
 
57
59
  def play_back_url(url)
@@ -72,12 +74,8 @@ module PuppetDebugger
72
74
  begin
73
75
  full_buffer += buf
74
76
  # unless this is puppet code, otherwise skip repl keywords
75
- if PuppetDebugger::InputResponders::Commands.command_list_regex.match(buf)
76
- debugger.out_buffer.write('>> ')
77
- else
78
- debugger.parser.parse_string(full_buffer)
79
- debugger.out_buffer.write('>> ')
80
- end
77
+ debugger.parser.parse_string(full_buffer) unless PuppetDebugger::InputResponders::Commands.command_list_regex.match(buf)
78
+ debugger.out_buffer.write('>> ')
81
79
  rescue Puppet::ParseErrorWithIssue => e
82
80
  if debugger.multiline_input?(e)
83
81
  full_buffer += "\n"
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Reset < InputResponderPlugin
5
- COMMAND_WORDS = %w(reset)
7
+ COMMAND_WORDS = %w[reset].freeze
6
8
  SUMMARY = 'Reset the debugger to a clean state.'
7
9
  COMMAND_GROUP = :context
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  debugger.set_scope(nil)
11
13
  debugger.set_remote_node_name(nil)
12
14
  debugger.set_node(nil)
13
15
  debugger.set_facts(nil)
14
16
  debugger.set_environment(nil)
15
17
  debugger.set_compiler(nil)
16
- #debugger.handle_input(":set loglevel #{debugger.log_level}")
18
+ # debugger.handle_input(":set loglevel #{debugger.log_level}")
17
19
  nil
18
20
  end
19
21
  end
@@ -1,20 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Resources < InputResponderPlugin
5
- COMMAND_WORDS = %w(resources)
7
+ COMMAND_WORDS = %w[resources].freeze
6
8
  SUMMARY = 'List all the resources current in the catalog.'
7
9
  COMMAND_GROUP = :scope
8
10
 
9
11
  def run(args = [])
10
- res = debugger.scope.compiler.catalog.resources.map do |res|
12
+ filter = args
13
+ resources = find_resources(debugger.catalog.resources, filter)
14
+ modified = resources.map do |res|
11
15
  res.to_s.gsub(/\[/, "['").gsub(/\]/, "']") # ensure the title has quotes
12
16
  end
13
- if !args.first.nil?
14
- res[args.first.to_i].ai
15
- else
16
- output = "Resources not shown in any specific order\n".warning
17
- output += res.ai
17
+ output = "Resources not shown in any specific order\n".warning
18
+ output + modified.ai
19
+ end
20
+
21
+ def find_resources(resources, filter = [])
22
+ return resources if filter.nil? || filter.empty?
23
+
24
+ filter_string = filter.join(' ').downcase
25
+ resources.find_all do |resource|
26
+ resource.name.to_s.downcase.include?(filter_string) || resource.type.to_s.downcase.include?(filter_string)
18
27
  end
19
28
  end
20
29
  end
@@ -1,28 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-debugger/input_responder_plugin'
2
4
  module PuppetDebugger
3
5
  module InputResponders
4
6
  class Set < InputResponderPlugin
5
- COMMAND_WORDS = %w(set :set)
7
+ COMMAND_WORDS = %w[set :set].freeze
6
8
  SUMMARY = 'Set the a puppet debugger config'
7
9
  COMMAND_GROUP = :scope
8
- KEYWORDS = %w(node loglevel)
9
- LOGLEVELS = %w(debug info)
10
+ KEYWORDS = %w[node loglevel].freeze
11
+ LOGLEVELS = %w[debug info].freeze
10
12
 
11
13
  def self.command_completion(buffer_words)
12
14
  next_word = buffer_words.shift
13
15
  case next_word
14
- when 'loglevel'
15
- if buffer_words.count > 0
16
- LOGLEVELS.grep(/^#{Regexp.escape(buffer_words.first)}/)
17
- else
18
- LOGLEVELS
19
- end
20
- when 'debug', 'info','node'
21
- []
22
- when nil
23
- %w(node loglevel)
16
+ when 'loglevel'
17
+ if buffer_words.count.positive?
18
+ LOGLEVELS.grep(/^#{Regexp.escape(buffer_words.first)}/)
24
19
  else
25
- KEYWORDS.grep(/^#{Regexp.escape(next_word)}/)
20
+ LOGLEVELS
21
+ end
22
+ when 'debug', 'info', 'node'
23
+ []
24
+ when nil
25
+ %w[node loglevel]
26
+ else
27
+ KEYWORDS.grep(/^#{Regexp.escape(next_word)}/)
26
28
  end
27
29
  end
28
30
 
@@ -37,24 +39,24 @@ module PuppetDebugger
37
39
  # args = input.split(' ')
38
40
  # args.shift # throw away the set
39
41
  case input.shift
40
- when /node/
41
- if name = input.shift
42
- output = "Resetting to use node #{name}"
43
- debugger.set_scope(nil)
44
- debugger.set_node(nil)
45
- debugger.set_facts(nil)
46
- debugger.set_environment(nil)
47
- debugger.set_compiler(nil)
48
- set_log_level(debugger.log_level)
49
- debugger.set_remote_node_name(name)
50
- else
51
- debugger.out_buffer.puts 'Must supply a valid node name'
52
- end
53
- when /loglevel/
54
- if level = input.shift
55
- set_log_level(level)
56
- output = "loglevel #{Puppet::Util::Log.level} is set"
57
- end
42
+ when /node/
43
+ if name = input.shift
44
+ output = "Resetting to use node #{name}"
45
+ debugger.set_scope(nil)
46
+ debugger.set_node(nil)
47
+ debugger.set_facts(nil)
48
+ debugger.set_environment(nil)
49
+ debugger.set_compiler(nil)
50
+ set_log_level(debugger.log_level)
51
+ debugger.set_remote_node_name(name)
52
+ else
53
+ debugger.out_buffer.puts 'Must supply a valid node name'
54
+ end
55
+ when /loglevel/
56
+ if level = input.shift
57
+ set_log_level(level)
58
+ output = "loglevel #{Puppet::Util::Log.level} is set"
59
+ end
58
60
  end
59
61
  output
60
62
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'puppet-debugger/input_responder_plugin'
4
+ module PuppetDebugger
5
+ module InputResponders
6
+ class Stacktrace < InputResponderPlugin
7
+ COMMAND_WORDS = %w[stacktrace].freeze
8
+ SUMMARY = 'Show the stacktrace for how we got here'
9
+ COMMAND_GROUP = :tools
10
+
11
+ # @return [Array]- returns a array of pp files that are involved in the stacktrace
12
+ def run(_args = [])
13
+ s = stacktrace
14
+ s.empty? ? 'stacktrace not available'.warning : s.ai
15
+ end
16
+
17
+ # @return [Array] - an array of files with line numbers
18
+ # @example
19
+ # [
20
+ # "/nwops/puppetlabs-peadm/spec/fixtures/modules/peadm/plans/status.pp:23",
21
+ # "/nwops/puppetlabs-peadm/spec/fixtures/modules/peadm/plans/status.pp:20"
22
+ # ]
23
+ def stacktrace
24
+ stack = Puppet::Pops::PuppetStack.stacktrace.find_all { |line| !line.include?('unknown') }
25
+ stack.each_with_object([]) do |item, acc|
26
+ acc << item.join(':')
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end