puppet-debugger 0.19.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +10 -27
  3. data/.rubocop.yml +64 -232
  4. data/.rubocop_todo.yml +89 -147
  5. data/CHANGELOG.md +12 -1
  6. data/Gemfile +7 -5
  7. data/README.md +4 -5
  8. data/Rakefile +11 -12
  9. data/bin/pdb +1 -1
  10. data/lib/awesome_print/ext/awesome_puppet.rb +10 -8
  11. data/lib/plugins/puppet-debugger/input_responders/benchmark.rb +5 -4
  12. data/lib/plugins/puppet-debugger/input_responders/classes.rb +4 -1
  13. data/lib/plugins/puppet-debugger/input_responders/classification.rb +4 -2
  14. data/lib/plugins/puppet-debugger/input_responders/commands.rb +18 -18
  15. data/lib/plugins/puppet-debugger/input_responders/datatypes.rb +11 -5
  16. data/lib/plugins/puppet-debugger/input_responders/environment.rb +4 -2
  17. data/lib/plugins/puppet-debugger/input_responders/exit.rb +4 -2
  18. data/lib/plugins/puppet-debugger/input_responders/facterdb_filter.rb +4 -2
  19. data/lib/plugins/puppet-debugger/input_responders/facts.rb +4 -2
  20. data/lib/plugins/puppet-debugger/input_responders/functions.rb +34 -32
  21. data/lib/plugins/puppet-debugger/input_responders/help.rb +4 -2
  22. data/lib/plugins/puppet-debugger/input_responders/krt.rb +4 -2
  23. data/lib/plugins/puppet-debugger/input_responders/play.rb +22 -24
  24. data/lib/plugins/puppet-debugger/input_responders/reset.rb +5 -3
  25. data/lib/plugins/puppet-debugger/input_responders/resources.rb +5 -2
  26. data/lib/plugins/puppet-debugger/input_responders/set.rb +34 -32
  27. data/lib/plugins/puppet-debugger/input_responders/stacktrace.rb +23 -0
  28. data/lib/plugins/puppet-debugger/input_responders/types.rb +6 -2
  29. data/lib/plugins/puppet-debugger/input_responders/vars.rb +6 -5
  30. data/lib/plugins/puppet-debugger/input_responders/whereami.rb +5 -3
  31. data/lib/puppet-debugger/cli.rb +118 -91
  32. data/lib/puppet-debugger/code/code_file.rb +13 -14
  33. data/lib/puppet-debugger/code/code_range.rb +5 -3
  34. data/lib/puppet-debugger/code/loc.rb +1 -1
  35. data/lib/puppet-debugger/debugger_code.rb +2 -0
  36. data/lib/puppet-debugger/hooks.rb +15 -16
  37. data/lib/puppet-debugger/input_responder_plugin.rb +54 -52
  38. data/lib/puppet-debugger/monkey_patches.rb +4 -1
  39. data/lib/puppet-debugger/plugin_test_helper.rb +9 -8
  40. data/lib/puppet-debugger/support.rb +27 -17
  41. data/lib/puppet-debugger/support/environment.rb +4 -4
  42. data/lib/puppet-debugger/support/errors.rb +25 -27
  43. data/lib/puppet-debugger/support/facts.rb +5 -5
  44. data/lib/puppet-debugger/support/node.rb +4 -5
  45. data/lib/puppet-debugger/support/scope.rb +19 -17
  46. data/lib/puppet-debugger/trollop.rb +38 -31
  47. data/lib/puppet-debugger/version.rb +1 -1
  48. data/lib/puppet/application/debugger.rb +141 -135
  49. data/output.json +1 -0
  50. data/puppet-debugger.gemspec +17 -16
  51. data/spec/awesome_print/ext/awesome_puppet_spec.rb +30 -30
  52. data/spec/fixtures/sample_start_debugger.pp +3 -2
  53. data/spec/hooks_spec.rb +33 -35
  54. data/spec/input_responder_plugin_spec.rb +7 -6
  55. data/spec/input_responders/benchmark_spec.rb +3 -1
  56. data/spec/input_responders/classes_spec.rb +12 -10
  57. data/spec/input_responders/classification_spec.rb +4 -2
  58. data/spec/input_responders/commands_spec.rb +2 -0
  59. data/spec/input_responders/datatypes_spec.rb +4 -3
  60. data/spec/input_responders/environment_spec.rb +2 -0
  61. data/spec/input_responders/exit_spec.rb +9 -11
  62. data/spec/input_responders/facterdb_filter_spec.rb +2 -0
  63. data/spec/input_responders/facts_spec.rb +2 -0
  64. data/spec/input_responders/functions_spec.rb +30 -28
  65. data/spec/input_responders/help_spec.rb +4 -2
  66. data/spec/input_responders/krt_spec.rb +3 -1
  67. data/spec/input_responders/play_spec.rb +10 -20
  68. data/spec/input_responders/reset_spec.rb +2 -0
  69. data/spec/input_responders/resources_spec.rb +3 -1
  70. data/spec/input_responders/set_spec.rb +3 -1
  71. data/spec/input_responders/stacktrace_spec.rb +15 -0
  72. data/spec/input_responders/types_spec.rb +2 -0
  73. data/spec/input_responders/vars_spec.rb +4 -4
  74. data/spec/input_responders/whereami_spec.rb +2 -0
  75. data/spec/pdb_spec.rb +0 -9
  76. data/spec/puppet/application/debugger_spec.rb +18 -19
  77. data/spec/puppet_debugger_spec.rb +81 -84
  78. data/spec/remote_node_spec.rb +1 -5
  79. data/spec/spec_helper.rb +22 -18
  80. data/spec/support_spec.rb +3 -5
  81. data/test_matrix.rb +1 -1
  82. metadata +48 -31
@@ -1,4 +1,15 @@
1
- ## Unreleased
1
+ ## 1.0
2
+ Released: 8/3/2020
3
+
4
+ This is a major revision with breaking changes, notibly the requirement of ruby 2.4 and puppet 5.5.
5
+
6
+ - Bump required ruby version to 2.4
7
+ - Bump required puppet version to puppet 5.5
8
+ - Add stacktrace plugin
9
+ - Add a pager for long output
10
+ - Remove puppet4 and older work arounds
11
+ - Use rubocop for better code quality
12
+ - Fix issue when the debugger was not loading the manfiest properely
2
13
 
3
14
  ## 0.19.0
4
15
  - Search datatypes with filter
data/Gemfile CHANGED
@@ -1,23 +1,25 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'http://rubygems.org'
3
4
  gem 'awesome_print', '~> 1.7'
4
5
  gem 'facterdb', '>= 0.5.0'
5
- gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 4.10.1'
6
6
  gem 'pluginator', '~> 1.5.0'
7
+ gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '>= 5.5'
7
8
  gem 'rb-readline'
8
9
  gem 'table_print'
10
+ gem 'tty-pager'
9
11
  group :test, :development do
10
12
  # ruby versions prior to 2.0 cannot install json_pure 2.0.2+
11
13
  gem 'bundler'
12
14
  gem 'CFPropertyList'
13
15
  gem 'pry'
14
16
  gem 'puppet-debugger', path: './'
15
- gem 'rake', '= 12.3.3'
17
+ gem 'rake', '~> 13.0'
16
18
  gem 'rdoc', '~> 3.12'
17
19
  gem 'release_me'
18
20
  gem 'rspec', '~> 3.6'
21
+ gem 'rubocop'
22
+ gem 'rubocop-performance'
23
+ gem 'rubocop-rspec'
19
24
  gem 'simplecov', '>= 0'
20
- gem 'rubocop', '= 0.48.0'
21
-
22
25
  end
23
-
data/README.md CHANGED
@@ -35,7 +35,7 @@ A interactive command line tool for evaluating and debugging the puppet language
35
35
  Please visit https://docs.puppet-debugger.com for more info.
36
36
 
37
37
  ## Compatibility
38
- Requires Puppet 3.8+ and only uses the future parser. Works with puppet 4-6.
38
+ Requires Puppet 5.5+, ruby 2.4+
39
39
 
40
40
  ## Production usage
41
41
  The puppet debugger is a developer tool that should only be used when writing puppet code. Although it might seem useful
@@ -64,8 +64,8 @@ and see what it would actual do when compiling a resource.
64
64
  Example Usage
65
65
  ```
66
66
  Ruby Version: 2.6.5
67
- Puppet Version: 6.14.0
68
- Puppet Debugger Version: 0.16.0
67
+ Puppet Version: 6.17.0
68
+ Puppet Debugger Version: 1.0.0
69
69
  Created by: NWOps <corey@nwops.io>
70
70
  Type "commands" for a list of debugger commands
71
71
  or "help" to show the help screen.
@@ -90,8 +90,7 @@ or "help" to show the help screen.
90
90
  "policy_version" => "29"
91
91
  }
92
92
  }
93
- 2:>>
94
-
93
+ 2:>>
95
94
 
96
95
  ```
97
96
 
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'rubygems'
@@ -9,8 +8,8 @@ require 'rake/testtask'
9
8
  begin
10
9
  Bundler.setup(:default, :development, :test)
11
10
  rescue Bundler::BundlerError => e
12
- $stderr.puts e.message
13
- $stderr.puts 'Run `bundle install` to install missing gems'
11
+ warn e.message
12
+ warn 'Run `bundle install` to install missing gems'
14
13
  exit e.status_code
15
14
  end
16
15
  require 'rake'
@@ -34,13 +33,14 @@ end
34
33
 
35
34
  desc 'Creates generic input_responder spec files'
36
35
  task :make_input_responder_tests do
37
- files = Dir.glob("lib/plugins/**/*.rb")
38
- new_files = files.collect do |pathname|
39
- orig_file = File.basename(pathname, ".*")
36
+ files = Dir.glob('lib/plugins/**/*.rb')
37
+ files.collect do |pathname|
38
+ orig_file = File.basename(pathname, '.*')
40
39
  test_file = File.join('spec', 'input_responders', "#{orig_file}_spec.rb")
41
- unless File.exist?(test_file)
42
- new_file = File.new(test_file, "w")
43
- contents = <<-EOS
40
+ next if File.exist?(test_file)
41
+
42
+ # new_file = File.new(test_file, "w")
43
+ contents = <<-OUT
44
44
  require 'spec_helper'
45
45
  require 'puppet-debugger'
46
46
  require 'puppet-debugger/plugin_test_helper'
@@ -50,8 +50,7 @@ task :make_input_responder_tests do
50
50
  let(:args) { [] }
51
51
 
52
52
  end
53
- EOS
54
- File.write(test_file, contents)
55
- end
53
+ OUT
54
+ File.write(test_file, contents)
56
55
  end
57
56
  end
data/bin/pdb CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  require 'puppet-debugger'
5
5
 
6
- puts "The debugger pdb command will be removed in a future release please use puppet-debugger or puppet debugger instead".warning
6
+ puts 'The debugger pdb command will be removed in a future release please use puppet-debugger or puppet debugger instead'.warning
7
7
  PuppetDebugger::Cli.start
@@ -52,6 +52,7 @@ module AwesomePrint
52
52
 
53
53
  def awesome_puppet_resource(object)
54
54
  return '' if object.nil?
55
+
55
56
  resource_object = object.to_ral
56
57
  awesome_puppet_type(resource_object)
57
58
  end
@@ -59,16 +60,17 @@ module AwesomePrint
59
60
  def awesome_puppet_type(object)
60
61
  return '' if object.nil?
61
62
  return object.to_s unless object.respond_to?(:name) && object.respond_to?(:title) && object.respond_to?(:to_hash)
62
- if Array.new.respond_to?(:to_h)
63
- # to_h is only supported in ruby 2.1+
64
- h = object.to_hash.merge(name: object.name, title: object.title).sort.to_h
65
- else
66
- h = object.to_hash.merge(name: object.name, title: object.title)
67
- end
68
- res_str = awesome_hash(JSON.parse(h.to_json)) #converting to json removes symbols
63
+
64
+ h = if [].respond_to?(:to_h)
65
+ # to_h is only supported in ruby 2.1+
66
+ object.to_hash.merge(name: object.name, title: object.title).sort.to_h
67
+ else
68
+ object.to_hash.merge(name: object.name, title: object.title)
69
+ end
70
+ res_str = awesome_hash(JSON.parse(h.to_json)) # converting to json removes symbols
69
71
  "#{object.class} #{res_str}"
70
72
  end
71
73
  end
72
74
  end
73
75
 
74
- AwesomePrint::Formatter.send(:include, AwesomePrint::Puppet)
76
+ AwesomePrint::Formatter.include AwesomePrint::Puppet
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'benchmark'
2
4
  require 'puppet-debugger/input_responder_plugin'
3
5
  module PuppetDebugger
4
6
  module InputResponders
5
7
  class Benchmark < InputResponderPlugin
6
- COMMAND_WORDS = %w(benchmark bm)
8
+ COMMAND_WORDS = %w[benchmark bm].freeze
7
9
  SUMMARY = 'Benchmark your Puppet code.'
8
10
  COMMAND_GROUP = :tools
9
11
 
10
12
  def run(args = [])
11
- if args.count > 0
13
+ if args.count.positive?
12
14
  enable(false)
13
15
  out = debugger.handle_input(args.first)
14
16
  disable
@@ -34,7 +36,6 @@ module PuppetDebugger
34
36
  'On'
35
37
  end
36
38
  end
37
-
38
39
  end
39
40
  end
40
- end
41
+ 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 Classes < InputResponderPlugin
5
- COMMAND_WORDS = %w(classes)
7
+ COMMAND_WORDS = %w[classes].freeze
6
8
  SUMMARY = 'List all the classes current in the catalog.'
7
9
  COMMAND_GROUP = :scope
8
10
 
@@ -14,6 +16,7 @@ module PuppetDebugger
14
16
 
15
17
  def find_classes(classes, filter = [])
16
18
  return classes if filter.nil? || filter.empty?
19
+
17
20
  filter_string = filter.join(' ').downcase
18
21
  classes.find_all do |klass|
19
22
  klass.downcase.include?(filter_string)
@@ -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 Classification < InputResponderPlugin
5
- COMMAND_WORDS = %w(classification)
7
+ COMMAND_WORDS = %w[classification].freeze
6
8
  SUMMARY = 'Show the classification details of the node.'
7
9
  COMMAND_GROUP = :node
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  debugger.node.classes.ai
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 Commands < InputResponderPlugin
5
- COMMAND_WORDS = %w(commands)
7
+ COMMAND_WORDS = %w[commands].freeze
6
8
  SUMMARY = 'List all available commands, aka. this screen'
7
9
  COMMAND_GROUP = :help
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  commands_list
11
13
  end
12
14
 
@@ -31,9 +33,9 @@ module PuppetDebugger
31
33
  def command_groups
32
34
  unless @command_groups
33
35
  @command_groups = {}
34
- self.class.command_output.each do | item|
36
+ self.class.command_output.each do |item|
35
37
  if @command_groups[item[:group]]
36
- @command_groups[item[:group]].merge!({ item[:words].first => item[:summary] })
38
+ @command_groups[item[:group]].merge!(item[:words].first => item[:summary])
37
39
  else
38
40
  @command_groups[item[:group]] = { item[:words].first => item[:summary] }
39
41
  end
@@ -43,12 +45,12 @@ module PuppetDebugger
43
45
  end
44
46
 
45
47
  def self.command_list_regex
46
- out = command_list.map {|n| "^#{n}"}.join('|')
47
- %r(#{out})
48
+ out = command_list.map { |n| "^#{n}" }.join('|')
49
+ /#{out}/
48
50
  end
49
51
 
50
52
  def self.command_list
51
- command_output.map{|f| f[:words] }.flatten
53
+ command_output.map { |f| f[:words] }.flatten
52
54
  end
53
55
 
54
56
  def self.command_output
@@ -56,22 +58,20 @@ module PuppetDebugger
56
58
  end
57
59
 
58
60
  def self.plugins
59
- begin
60
- debug_plugins = Pluginator.find('puppet-debugger')
61
- debug_plugins["input_responders"]
62
- rescue NoMethodError => e
63
- raise PuppetDebugger::Exception::InvalidCommand.new(message: "Unsupported gem version. Please update with: gem update --system")
64
- end
61
+ debug_plugins = Pluginator.find('puppet-debugger')
62
+ debug_plugins['input_responders']
63
+ rescue NoMethodError
64
+ raise PuppetDebugger::Exception::InvalidCommand.new(message: 'Unsupported gem version. Please update with: gem update --system')
65
65
  end
66
66
 
67
67
  # @param name [String] - the name of the command that is associated with a plugin
68
68
  # @return [PuppetDebugger::InputResponders::InputResponderPlugin]
69
69
  def self.plugin_from_command(name)
70
- p = plugins.find {|p| p::COMMAND_WORDS.include?(name)}
71
- raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{name}") unless p
72
- p
73
- end
70
+ plug = plugins.find { |p| p::COMMAND_WORDS.include?(name) }
71
+ raise PuppetDebugger::Exception::InvalidCommand.new(message: "invalid command #{name}") unless plug
74
72
 
73
+ plug
74
+ end
75
75
  end
76
76
  end
77
- end
77
+ 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 Datatypes < InputResponderPlugin
5
- COMMAND_WORDS = %w(datatypes)
7
+ COMMAND_WORDS = %w[datatypes].freeze
6
8
  SUMMARY = 'List all the datatypes available in the environment.'
7
9
  COMMAND_GROUP = :environment
8
10
 
@@ -14,6 +16,7 @@ module PuppetDebugger
14
16
 
15
17
  def find_datatypes(datatypes, filter = [])
16
18
  return datatypes if filter.nil? || filter.empty?
19
+
17
20
  filter_string = filter.join(' ').downcase
18
21
  datatypes.find_all do |datatype|
19
22
  datatype.downcase.include?(filter_string)
@@ -27,15 +30,19 @@ module PuppetDebugger
27
30
  files.map do |f|
28
31
  m = File.read(f).match(/type\s([a-z\d\:_]+)/i)
29
32
  next if m =~ /type|alias/ # can't figure out the best way to filter type and alias out
33
+
30
34
  m[1] if m && m[1] =~ /::/
31
35
  end.uniq.compact
32
36
  end
33
37
 
38
+ # loaders.instance_variable_get(:@loaders_by_name)['boltlib']
39
+ # [:func_4x, :func_4xpp, :func_3x, :datatype, :type_pp,
40
+ # :resource_type_pp, :plan, :task]
34
41
  # @return [Array[String]] - a list of core data types
35
42
  def core_datatypes
36
- loaders.implementation_registry
37
- .instance_variable_get(:'@implementations_per_type_name')
38
- .keys.find_all { |t| t !~ /::/ }
43
+ loaders.implementation_registry.instance_variable_get(:@parent)
44
+ .instance_variable_get(:@implementations_per_type_name)
45
+ .keys.find_all { |t| t !~ /::/ }
39
46
  end
40
47
 
41
48
  # @return [Array[String]] - combined list of core data types and environment data types
@@ -46,7 +53,6 @@ module PuppetDebugger
46
53
  end
47
54
  core_datatypes + environment_data_types
48
55
  end
49
-
50
56
  end
51
57
  end
52
58
  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 Environment < InputResponderPlugin
5
- COMMAND_WORDS = %w(environment)
7
+ COMMAND_WORDS = %w[environment].freeze
6
8
  SUMMARY = 'Show the current environment name'
7
9
  COMMAND_GROUP = :context
8
10
 
9
- def run(args = [])
11
+ def run(_args = [])
10
12
  "Puppet Environment: #{debugger.puppet_env_name}"
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 Exit < InputResponderPlugin
5
- COMMAND_WORDS = %w(exit)
7
+ COMMAND_WORDS = %w[exit].freeze
6
8
  SUMMARY = 'Quit Puppet Debugger.'
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