puppet-debugger 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3a943d793cc70f63e92cffc0843d0f4e9dfee03
4
- data.tar.gz: 892a71554b9c5e156de87363341c3ef04bc8cc7a
3
+ metadata.gz: 1d8a6792ac8befb2af4d9769af6b2ef803ae018c
4
+ data.tar.gz: d23e13a008ddf75f72883db3e79bab7e6cfb8ef8
5
5
  SHA512:
6
- metadata.gz: 35605789439801670e2899f17de1e10ef8109d6cb998ca6766993ba403dee1ab990a02faf0e43ae619f58c2d6ee2c83fa1b240d9eb9b88d51d2fce9011a8064e
7
- data.tar.gz: bb774bc6493905d0fc280c09862e33462e4ea363c081d523b2ac2958f0f03e98a06d46f3593ad26b87e24380bed1131c9b7d233250890f1337069d94fd52613d
6
+ metadata.gz: cd3c1d7e97f909563ea3d1fa6f08ff836e8fc16732fd151b6f1ab80fce6fd96c1a9199bcc936cb58302340b40c2dd991aa97b60ff06c0729c0a76067bd00dd94
7
+ data.tar.gz: 1006a7f6453775c5d6b8ed307224fad0236c389bd404c475a9d24b4404153652676504d5c315132306888032f3b98ad138b50e3da296c040fd11c4dfb663501b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 0.12.1
4
+
5
+ - Fixes issue with command completion
6
+ - Fixes unqualified runtime error
7
+
3
8
  ## 0.12.0
4
9
 
5
10
  - Adds ability to list resource parameters as they were evaluated
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'puppet'
4
- require 'readline'
5
- require 'json'
6
- require 'puppet-debugger/support'
7
- require 'pluginator'
8
- require 'puppet-debugger/hooks'
9
- require 'forwardable'
3
+ require "puppet"
4
+ require "readline"
5
+ require "json"
6
+ require "puppet-debugger/support"
7
+ require "pluginator"
8
+ require "puppet-debugger/hooks"
9
+ require "forwardable"
10
+ require "plugins/puppet-debugger/input_responders/functions"
11
+ require "plugins/puppet-debugger/input_responders/datatypes"
10
12
 
11
13
  module PuppetDebugger
12
14
  class Cli
@@ -23,19 +25,19 @@ module PuppetDebugger
23
25
  Puppet[:static_catalogs] = false unless Puppet.settings[:static_catalogs].nil?
24
26
  set_remote_node_name(options[:node_name])
25
27
  initialize_from_scope(options[:scope])
26
- @log_level = 'notice'
28
+ @log_level = "notice"
27
29
  @out_buffer = options[:out_buffer] || $stdout
28
30
  @html_mode = options[:html_mode] || false
29
31
  @source_file = options[:source_file] || nil
30
32
  @source_line_num = options[:source_line] || nil
31
33
  @in_buffer = options[:in_buffer] || $stdin
32
- Readline.completion_append_character = ''
33
- Readline.basic_word_break_characters = ' '
34
+ Readline.completion_append_character = ""
35
+ Readline.basic_word_break_characters = " "
34
36
  Readline.completion_proc = command_completion
35
37
  AwesomePrint.defaults = {
36
38
  html: @html_mode,
37
39
  sort_keys: true,
38
- indent: 2
40
+ indent: 2,
39
41
  }
40
42
  end
41
43
 
@@ -48,7 +50,7 @@ module PuppetDebugger
48
50
  next key_words.grep(/^#{Regexp.escape(input)}/) if words.empty?
49
51
  first_word = words.shift
50
52
  plugins = PuppetDebugger::InputResponders::Commands.plugins.find_all do |p|
51
- p::COMMAND_WORDS.find { |word| word.start_with?(first_word)}
53
+ p::COMMAND_WORDS.find { |word| word.start_with?(first_word) }
52
54
  end
53
55
  if plugins.count == 1 and /\A#{first_word}\s/.match(Readline.line_buffer)
54
56
  plugins.first.command_completion(words)
@@ -69,6 +71,7 @@ module PuppetDebugger
69
71
  variables = scope.to_hash.keys
70
72
  # prepend a :: to topscope variables
71
73
  scoped_vars = variables.map { |k, _v| scope.compiler.topscope.exist?(k) ? "$::#{k}" : "$#{k}" }
74
+ PuppetDebugger::InputResponders::Functions.instance.debugger = self
72
75
  funcs = PuppetDebugger::InputResponders::Functions.instance.func_list
73
76
  PuppetDebugger::InputResponders::Datatypes.instance.debugger = self
74
77
  (scoped_vars + funcs + static_responder_list + PuppetDebugger::InputResponders::Datatypes.instance.all_data_types).uniq.sort
@@ -93,7 +96,7 @@ module PuppetDebugger
93
96
  # don't return anything or returns nil if item is not in the catalog
94
97
  end
95
98
 
96
- #
99
+ #
97
100
  # @return [Array] - returns a formatted array
98
101
  # @param types [Array] - an array or string
99
102
  def expand_resource_type(types)
@@ -101,7 +104,7 @@ module PuppetDebugger
101
104
  end
102
105
 
103
106
  def contains_resources?(result)
104
- ! Array(result).flatten.find {|r| r.class.to_s =~ /Puppet::Pops::Types/ }.nil?
107
+ !Array(result).flatten.find { |r| r.class.to_s =~ /Puppet::Pops::Types/ }.nil?
105
108
  end
106
109
 
107
110
  def normalize_output(result)
@@ -125,21 +128,21 @@ module PuppetDebugger
125
128
  def handle_input(input)
126
129
  raise ArgumentError unless input.instance_of?(String)
127
130
  begin
128
- output = ''
131
+ output = ""
129
132
  case input.strip
130
133
  when PuppetDebugger::InputResponders::Commands.command_list_regex
131
- args = input.split(' ')
134
+ args = input.split(" ")
132
135
  command = args.shift
133
136
  plugin = PuppetDebugger::InputResponders::Commands.plugin_from_command(command)
134
137
  output = plugin.execute(args, self)
135
138
  return out_buffer.puts output
136
- when '_'
139
+ when "_"
137
140
  output = " => #{@last_item}"
138
141
  else
139
142
  result = puppet_eval(input)
140
143
  @last_item = result
141
144
  output = normalize_output(result)
142
- output = output.nil? ? '' : output.ai
145
+ output = output.nil? ? "" : output.ai
143
146
  end
144
147
  rescue PuppetDebugger::Exception::InvalidCommand => e
145
148
  output = e.message.fatal
@@ -161,13 +164,13 @@ module PuppetDebugger
161
164
  exit 1 # this can sometimes causes tests to fail
162
165
  rescue PuppetDebugger::Exception::Error => e
163
166
  output = e.message.fatal
164
- rescue RuntimeException => e
167
+ rescue ::RuntimeError => e
165
168
  output = e.message.fatal
166
169
  out_buffer.puts output
167
170
  exit 1
168
171
  end
169
172
  unless output.empty?
170
- out_buffer.print ' => '
173
+ out_buffer.print " => "
171
174
  out_buffer.puts output unless output.empty?
172
175
  exec_hook :after_output, out_buffer, self, self
173
176
  end
@@ -206,7 +209,7 @@ or "help" to show the help screen.
206
209
  # input
207
210
  def read_loop
208
211
  line_number = 1
209
- full_buffer = ''
212
+ full_buffer = ""
210
213
  while buf = Readline.readline("#{line_number}:#{extra_prompt}>> ", true)
211
214
  begin
212
215
  full_buffer += buf
@@ -217,14 +220,14 @@ or "help" to show the help screen.
217
220
  parser.parse_string(full_buffer)
218
221
  rescue Puppet::ParseErrorWithIssue => e
219
222
  if multiline_input?(e)
220
- out_buffer.print ' '
223
+ out_buffer.print " "
221
224
  full_buffer += "\n"
222
225
  next
223
226
  end
224
227
  end
225
228
  end
226
229
  handle_input(full_buffer)
227
- full_buffer = ''
230
+ full_buffer = ""
228
231
  end
229
232
  end
230
233
  end
@@ -239,7 +242,7 @@ or "help" to show the help screen.
239
242
  repl_obj = PuppetDebugger::Cli.new(options)
240
243
  options[:play] = options[:play].path if options[:play].respond_to?(:path)
241
244
  # TODO: make the output optional so we can have different output destinations
242
- repl_obj.handle_input('whereami') if options[:source_file] && options[:source_line]
245
+ repl_obj.handle_input("whereami") if options[:source_file] && options[:source_line]
243
246
  repl_obj.handle_input("play #{options[:play]}") if options[:play]
244
247
  repl_obj.read_loop unless options[:run_once]
245
248
  end
@@ -250,10 +253,10 @@ or "help" to show the help screen.
250
253
  # @param [Hash] puppet scope object
251
254
  def self.start(options = { scope: nil })
252
255
  opts = Trollop.options do
253
- opt :play, 'Url or file to load from', required: false, type: String
254
- opt :run_once, 'Evaluate and quit', required: false, default: false
255
- opt :node_name, 'Remote Node to grab facts from', required: false, type: String
256
- opt :quiet, 'Do not display banner', required: false, default: false
256
+ opt :play, "Url or file to load from", required: false, type: String
257
+ opt :run_once, "Evaluate and quit", required: false, default: false
258
+ opt :node_name, "Remote Node to grab facts from", required: false, type: String
259
+ opt :quiet, "Do not display banner", required: false, default: false
257
260
  end
258
261
  options = opts.merge(options)
259
262
  puts print_repl_desc unless options[:quiet]
@@ -261,11 +264,11 @@ or "help" to show the help screen.
261
264
  repl_obj = PuppetDebugger::Cli.new(options)
262
265
  if options[:play]
263
266
  repl_obj.handle_input("play #{options[:play]}")
264
- elsif ARGF.filename != '-'
267
+ elsif ARGF.filename != "-"
265
268
  # when the user supplied a file name without using the args (stdin)
266
269
  path = File.expand_path(ARGF.filename)
267
270
  repl_obj.handle_input("play #{path}")
268
- elsif (ARGF.filename == '-') && (!STDIN.tty? && !STDIN.closed?)
271
+ elsif (ARGF.filename == "-") && (!STDIN.tty? && !STDIN.closed?)
269
272
  # when the user supplied a file content using stdin, aka. cat,pipe,echo or redirection
270
273
  input = ARGF.read
271
274
  repl_obj.handle_input(input)
@@ -8,7 +8,7 @@ module PuppetDebugger
8
8
  extend Forwardable
9
9
  attr_accessor :debugger
10
10
  def_delegators :debugger, :scope, :node, :environment, :loaders, :puppet_environment,
11
- :add_hook, :handle_input, :delete_hook, :puppet_lib_dir, :modules_paths
11
+ :add_hook, :handle_input, :delete_hook, :puppet_lib_dir
12
12
  def_delegators :scope, :compiler, :catalog
13
13
  def_delegators :node, :facts
14
14
 
@@ -17,6 +17,10 @@ module PuppetDebugger
17
17
  self::COMMAND_WORDS
18
18
  end
19
19
 
20
+ def modules_paths
21
+ debugger.puppet_environment.full_modulepath
22
+ end
23
+
20
24
  # @return [String] a summary of the plugin
21
25
  def self.summary
22
26
  self::SUMMARY
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PuppetDebugger
4
- VERSION = '0.12.0'
4
+ VERSION = "0.12.1"
5
5
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
- require 'stringio'
5
- describe 'PuppetDebugger' do
3
+ require "spec_helper"
4
+ require "stringio"
5
+ describe "PuppetDebugger" do
6
6
  let(:resource) do
7
7
  "service{'httpd': ensure => running}"
8
8
  end
9
9
 
10
10
  before(:each) do
11
- debugger.handle_input('reset')
11
+ debugger.handle_input("reset")
12
12
  end
13
13
 
14
14
  let(:output) do
@@ -31,10 +31,10 @@ describe 'PuppetDebugger' do
31
31
  debugger.parser.evaluate_string(debugger.scope, input)
32
32
  end
33
33
 
34
- describe 'native classes' do
35
- describe 'create' do
34
+ describe "native classes" do
35
+ describe "create" do
36
36
  let(:input) do
37
- 'class testfoo {}'
37
+ "class testfoo {}"
38
38
  end
39
39
  let(:debugger_output) do
40
40
  "\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"Testfoo\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Class[Testfoo]\"\e[0m\n}\n"
@@ -42,45 +42,45 @@ describe 'PuppetDebugger' do
42
42
  it do
43
43
  debugger.handle_input(input)
44
44
  expect(output.string).to eq("\n")
45
- expect(debugger.known_resource_types[:hostclasses]).to include('testfoo')
45
+ expect(debugger.known_resource_types[:hostclasses]).to include("testfoo")
46
46
  end
47
47
  it do
48
48
  debugger.handle_input(input)
49
- debugger.handle_input('include testfoo')
50
- expect(debugger.scope.compiler.catalog.classes).to include('testfoo')
49
+ debugger.handle_input("include testfoo")
50
+ expect(debugger.scope.compiler.catalog.classes).to include("testfoo")
51
51
  end
52
52
  it do
53
53
  debugger.handle_input(input)
54
- debugger.handle_input('include testfoo')
55
- expect(debugger.scope.compiler.catalog.resources.map(&:name)).to include('Testfoo')
54
+ debugger.handle_input("include testfoo")
55
+ expect(debugger.scope.compiler.catalog.resources.map(&:name)).to include("Testfoo")
56
56
  end
57
57
  end
58
58
  end
59
59
 
60
- describe 'native definitions' do
61
- describe 'create' do
60
+ describe "native definitions" do
61
+ describe "create" do
62
62
  let(:input) do
63
- 'define testfoodefine {}'
63
+ "define testfoodefine {}"
64
64
  end
65
65
  let(:debugger_output) do
66
66
  "\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"some_name\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Testfoo[some_name]\"\e[0m\n}\n"
67
67
  end
68
68
  it do
69
69
  debugger.handle_input(input)
70
- expect(debugger.scope.environment.known_resource_types.definitions.keys).to include('testfoodefine')
70
+ expect(debugger.scope.environment.known_resource_types.definitions.keys).to include("testfoodefine")
71
71
  expect(output.string).to eq("\n")
72
72
  end
73
73
  it do
74
74
  debugger.handle_input(input)
75
75
  debugger.handle_input("testfoodefine{'some_name':}")
76
- expect(debugger.scope.compiler.resources.collect(&:name)).to include('some_name')
77
- expect(debugger.scope.compiler.resources.collect(&:type)).to include('Testfoodefine')
76
+ expect(debugger.scope.compiler.resources.collect(&:name)).to include("some_name")
77
+ expect(debugger.scope.compiler.resources.collect(&:type)).to include("Testfoodefine")
78
78
  expect(output.string).to include("\n => Puppet::Type::Component")
79
79
  end
80
80
  end
81
81
  end
82
82
 
83
- describe 'key_words' do
83
+ describe "key_words" do
84
84
  it do
85
85
  expect(debugger.key_words.count).to be >= 30 if supports_datatypes?
86
86
  end
@@ -90,7 +90,7 @@ describe 'PuppetDebugger' do
90
90
  end
91
91
  end
92
92
 
93
- describe 'native functions', native_functions: true do
93
+ describe "native functions", native_functions: true do
94
94
  let(:func) do
95
95
  <<-EOF
96
96
  function debugger::bool2http($arg) {
@@ -105,12 +105,12 @@ describe 'PuppetDebugger' do
105
105
  before(:each) do
106
106
  debugger.handle_input(func)
107
107
  end
108
- describe 'create' do
109
- it 'shows function' do
108
+ describe "create" do
109
+ it "shows function" do
110
110
  expect(output.string).to eq("\n")
111
111
  end
112
112
  end
113
- describe 'run' do
113
+ describe "run" do
114
114
  let(:input) do
115
115
  <<-EOF
116
116
  debugger::bool2http(false)
@@ -118,37 +118,31 @@ describe 'PuppetDebugger' do
118
118
  end
119
119
  it do
120
120
  debugger.handle_input(input)
121
- expect(output.string).to include('Off')
121
+ expect(output.string).to include("Off")
122
122
  end
123
123
  end
124
124
  end
125
125
 
126
-
127
-
128
-
129
-
130
- describe 'returns a array of resource_types' do
131
- it 'returns resource type' do
132
- expect(resource_types.first.class.to_s).to eq('Puppet::Pops::Types::PResourceType')
126
+ describe "returns a array of resource_types" do
127
+ it "returns resource type" do
128
+ expect(resource_types.first.class.to_s).to eq("Puppet::Pops::Types::PResourceType")
133
129
  end
134
130
  end
135
131
 
136
-
137
-
138
- describe 'empty' do
132
+ describe "empty" do
139
133
  let(:input) do
140
- ''
134
+ ""
141
135
  end
142
- it 'can run' do
136
+ it "can run" do
143
137
  debugger_output = "\n"
144
138
  debugger.handle_input(input)
145
139
  expect(output.string).to eq(debugger_output)
146
140
  end
147
- describe 'space' do
141
+ describe "space" do
148
142
  let(:input) do
149
- ' '
143
+ " "
150
144
  end
151
- it 'can run' do
145
+ it "can run" do
152
146
  debugger_output = "\n"
153
147
  debugger.handle_input(input)
154
148
  expect(output.string).to eq(debugger_output)
@@ -156,111 +150,114 @@ describe 'PuppetDebugger' do
156
150
  end
157
151
  end
158
152
 
159
- describe 'variables' do
153
+ describe "variables" do
160
154
  let(:input) do
161
155
  "$file_path = '/tmp/test2.txt'"
162
156
  end
163
- it 'can process a variable' do
157
+ it "can process a variable" do
164
158
  debugger.handle_input(input)
165
159
  expect(output.string).to match(/\/tmp\/test2.txt/)
166
160
  end
167
161
  end
168
162
 
169
- describe 'resource' do
163
+ describe "resource" do
170
164
  let(:input) do
171
165
  "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
172
166
  end
173
- it 'can process a resource' do
167
+ it "can process a resource" do
174
168
  debugger_output = /Puppet::Type::File/
175
169
  debugger.handle_input(input)
176
170
  expect(output.string).to match(debugger_output)
177
171
  end
178
172
  end
179
173
 
180
- describe 'bad input' do
174
+ describe "bad input" do
181
175
  let(:input) do
182
- 'Service{'
176
+ "Service{"
183
177
  end
184
- it 'can process' do
178
+ it "can process" do
185
179
  debugger.handle_input(input)
186
180
  expect(output.string).to match(%r(Syntax error at end of))
187
181
  end
188
182
  end
189
183
 
190
- describe 'map block' do
184
+ describe "map block" do
191
185
  let(:input) do
192
186
  "['/tmp/test3', '/tmp/test4'].map |String $path| { file{$path: ensure => present} }"
193
187
  end
194
- it 'can process a each block' do
188
+ it "can process a each block" do
195
189
  debugger_output = /Puppet::Type::File/
196
190
  debugger.handle_input(input)
197
191
  expect(output.string).to match(debugger_output)
198
192
  end
199
193
  end
200
194
 
201
- describe 'each block' do
195
+ describe "each block" do
202
196
  let(:input) do
203
197
  "['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }"
204
198
  end
205
- it 'can process a each block' do
199
+ it "can process a each block" do
206
200
  debugger.handle_input(input)
207
201
  expect(output.string).to match(/\/tmp\/test3/)
208
202
  expect(output.string).to match(/\/tmp\/test4/)
209
203
  end
210
204
  end
211
205
 
212
- describe 'string' do
206
+ describe "string" do
213
207
  let(:input) do
214
- 'String'
208
+ "String"
215
209
  end
216
- it 'shows type' do
210
+ it "shows type" do
217
211
  debugger.handle_input(input)
218
212
  expect(output.string).to eq("\n => String\n")
219
213
  end
220
214
  end
221
- describe 'Array', type_function: true do
215
+ describe "Array", type_function: true do
222
216
  let(:input) do
223
- 'type([1,2,3,4])'
217
+ "type([1,2,3,4])"
224
218
  end
225
- it 'shows type' do
226
- if Gem::Version.new(Puppet.version) > Gem::Version.new('4.4')
219
+ it "shows type" do
220
+ if Gem::Version.new(Puppet.version) > Gem::Version.new("4.4")
227
221
  debugger.handle_input(input)
228
222
  expect(output.string.strip.split("\n").count).to eq(6)
229
223
  end
230
224
  end
231
225
  end
232
226
 
233
- describe 'multi diemension array' do
227
+ describe "multi diemension array" do
234
228
  let(:input) do
235
- '[[1, [23,4], [22], [1,[2232]]]]'
229
+ "[[1, [23,4], [22], [1,[2232]]]]"
236
230
  end
237
-
238
- it 'handles multi array' do
231
+
232
+ it "handles multi array" do
239
233
  debugger.handle_input(input)
240
- expect(output.string.count('[')).to eq(17)
234
+ expect(output.string.count("[")).to be >= 17
241
235
  end
242
-
243
236
  end
244
237
 
245
- describe 'command_completion' do
246
- it 'should complete on tabs' do
238
+ describe "command_completion" do
239
+ it "should complete on tabs" do
247
240
  allow(Readline).to receive(:line_buffer).and_return("\n")
248
241
  expect(debugger.command_completion.call("").count).to be >= 200
249
242
  end
243
+
244
+ it "#key_words" do
245
+ expect(debugger.key_words.count).to be >= 100
246
+ end
250
247
  end
251
248
 
252
- describe 'error message' do
249
+ describe "error message" do
253
250
  let(:input) do
254
251
  "file{'/tmp/test': ensure => present, contact => 'blah'}"
255
252
  end
256
- if Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')
257
- it 'show error message' do
253
+ if Gem::Version.new(Puppet.version) >= Gem::Version.new("4.0")
254
+ it "show error message" do
258
255
  debugger_output = /no\ parameter\ named\ 'contact'/
259
256
  debugger.handle_input(input)
260
257
  expect(output.string).to match(debugger_output)
261
258
  end
262
259
  else
263
- it 'show error message' do
260
+ it "show error message" do
264
261
  debugger_output = /Invalid\ parameter\ contact/
265
262
  debugger.handle_input(input)
266
263
  expect(output.string).to match(debugger_output)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-20 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: table_print