puppet-debugger 0.6.0 → 0.6.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: 857afe5c153e6dbdce56459291318d984689a28f
4
- data.tar.gz: c8c80c82ef553716ac98bf59c6a3175f8a11235a
3
+ metadata.gz: 44f5198a38560ebf262df1bb5d9fb27b4689f6d0
4
+ data.tar.gz: 76718414d5e49a617b755e6157f29b2188ff52cf
5
5
  SHA512:
6
- metadata.gz: 0fd7ebb96bef948c27045478ff96f872e22bcd98b2bcf4c8c2b44087eb7d75efaa1760327c9becdc8be2eb6b62ba1e6cf6bc5f147b00d98db1135410e0af27ed
7
- data.tar.gz: d2440f621ba7b0fe0111fa7735fd7cd8a53f1e6832cf7c1eba073149ebb8bd8c7d1bd15d6d5559766f1a2303194155be35d2edbdfd40d23201ac1ba50fb478d0
6
+ metadata.gz: 84b776b0a55d4d9cc116d4bf5a9ef8d67ecde7a8b6ac357b9f9af5dd990c555f258de0ea87ba1c5a359733ff8ec6524eac4e60d0a66d4858e8dbb4a0299a2c1c
7
+ data.tar.gz: d47bae21bef89a828e225bcb9095bb4bd1c7a40af174891ae4c17bd69eb487795deff60718ccac0aa9b1e1e7e48fa433b6ed140386e69418be2b29ce79aa00b0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ ## 0.6.1
2
+ * Adds benchmark feature
1
3
  ## 0.6.0
2
4
  * Adds ability to list puppet types
3
5
  * Adds ability to list puppet datatypes
@@ -97,10 +97,11 @@ module PuppetDebugger
97
97
  begin
98
98
  output = ''
99
99
  case input
100
- when /^play|^classification|^whereami|^facterdb_filter|^facts|^datatypes|^types|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/
100
+ when /^play|^classification|^whereami|^facterdb_filter|^facts|^datatypes|^types|^vars|^functions|^classes|^resources|^krt|^environment|^benchmark|^reset|^help/
101
101
  args = input.split(' ')
102
102
  command = args.shift.to_sym
103
103
  output = send(command, args) if respond_to?(command)
104
+ @bencmark = false
104
105
  return out_buffer.puts output
105
106
  when /exit/
106
107
  exit 0
@@ -112,11 +113,7 @@ module PuppetDebugger
112
113
  result = puppet_eval(input)
113
114
  @last_item = result
114
115
  output = normalize_output(result)
115
- output = if output.nil?
116
- ''
117
- else
118
- output.ai
119
- end
116
+ output = output.nil? ? '' : output.ai
120
117
  end
121
118
  rescue LoadError => e
122
119
  output = e.message.fatal
@@ -150,7 +147,8 @@ Puppet Version: #{Puppet.version}
150
147
  Puppet Debugger Version: #{PuppetDebugger::VERSION}
151
148
  Created by: NWOps <corey@nwops.io>
152
149
  Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "classes",
153
- "play", "classification", "types", "datatypes", "reset", or "help" for more information.
150
+ "play", "classification", "types", "datatypes", "benchmark",
151
+ "reset", or "help" for more information.
154
152
 
155
153
  EOT
156
154
  output
@@ -175,7 +173,7 @@ Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "clas
175
173
  def read_loop
176
174
  line_number = 1
177
175
  full_buffer = ''
178
- while buf = Readline.readline("#{line_number}:>> ", true)
176
+ while buf = Readline.readline("#{line_number}:#{$extra_prompt}>> ", true)
179
177
  begin
180
178
  full_buffer += buf
181
179
  # unless this is puppet code, otherwise skip repl keywords
@@ -7,6 +7,33 @@ module PuppetDebugger
7
7
  resources classes whereami datatypes play reset help)
8
8
  end
9
9
 
10
+ def disable_benchmark
11
+ $benchmark = false
12
+ $extra_prompt = ''
13
+ 'Off'
14
+ end
15
+
16
+ def enable_benchmark(show_status = false)
17
+ require 'benchmark'
18
+ $benchmark = true
19
+ if show_status
20
+ $extra_prompt = 'BM'
21
+ 'On'
22
+ end
23
+ end
24
+
25
+ def benchmark(args = [])
26
+ if args.count > 0
27
+ enable_benchmark(false)
28
+ out = handle_input(args.first)
29
+ disable_benchmark
30
+ out
31
+ else
32
+ status = $benchmark ? disable_benchmark : enable_benchmark(true)
33
+ "Benchmark Mode #{status}"
34
+ end
35
+ end
36
+
10
37
  def datatypes(_args = [])
11
38
  types = all_data_types
12
39
  return types.sort.ai if types.instance_of?(Array)
@@ -135,7 +135,16 @@ module PuppetDebugger
135
135
  global_scope: scope, loaders: scope.compiler.loaders }, 'For puppet-debugger') do
136
136
  # because the repl is not a module we leave the modname blank
137
137
  scope.environment.known_resource_types.import_ast(ast, '')
138
- parser.evaluate_string(scope, input, File.expand_path(file))
138
+
139
+ if $benchmark
140
+ result = nil
141
+ time = Benchmark.realtime do
142
+ result = parser.evaluate_string(scope, input, File.expand_path(file))
143
+ end
144
+ [result, "Time elapsed #{(time*1000).round(2)} ms"]
145
+ else
146
+ parser.evaluate_string(scope, input, File.expand_path(file))
147
+ end
139
148
  end
140
149
  end
141
150
 
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module PuppetDebugger
3
- VERSION = '0.6.0'
3
+ VERSION = '0.6.1'
4
4
  end
@@ -180,7 +180,7 @@ describe 'PuppetDebugger' do
180
180
  'help'
181
181
  end
182
182
  it 'can show the help screen' do
183
- expected_debugger_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"whereami\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"types\", \"datatypes\", \"reset\", or \"help\" for more information.\n\n/
183
+ expected_debugger_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"whereami\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"types\", \"datatypes\", \"benchmark\",\n \"reset\", or \"help\" for more information.\n\n/
184
184
  debugger.handle_input(input)
185
185
  expect(output.string).to match(/Ruby Version: #{RUBY_VERSION}\n/)
186
186
  expect(output.string).to match(/Puppet Version: \d.\d.\d\n/)
@@ -507,4 +507,33 @@ describe 'PuppetDebugger' do
507
507
  end
508
508
  end
509
509
  end
510
+
511
+ describe 'benchmark' do
512
+ let(:input) do
513
+ "benchmark md5('12345')"
514
+ end
515
+ describe 'mode' do
516
+ before(:each) do
517
+ debugger.handle_input('benchmark') # enable
518
+ end
519
+ it 'enable' do
520
+ debugger.handle_input("md5('12345')")
521
+ expect(output.string).to match(/Benchmark\ Mode\ On/)
522
+ expect(output.string).to match(/Time\ elapsed/)
523
+ end
524
+ it 'disable' do
525
+ debugger.handle_input('benchmark') # disable
526
+ expect(output.string).to match(/Benchmark\ Mode\ Off/)
527
+ end
528
+ end
529
+
530
+ describe 'onetime' do
531
+ it 'run' do
532
+ debugger.handle_input("benchmark md5('12345')")
533
+ expect(output.string).to_not match(/Benchmark\ Mode\ On/)
534
+ expect(output.string).to_not match(/Benchmark\ Mode\ Off/)
535
+ expect(output.string).to match(/Time\ elapsed/)
536
+ end
537
+ end
538
+ end
510
539
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.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: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: facterdb
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.3.8
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.8
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: awesome_print
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.12'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.12'
69
69
  description: A interactive command line tool for evaluating and debugging the puppet
@@ -77,15 +77,15 @@ extra_rdoc_files:
77
77
  - LICENSE.txt
78
78
  - README.md
79
79
  files:
80
- - .dockerignore
81
- - .document
82
- - .gitignore
83
- - .gitlab-ci.yml
84
- - .release_me.yaml
85
- - .rspec
86
- - .rubocop.yml
87
- - .rubocop_todo.yml
88
- - .ruby-version
80
+ - ".dockerignore"
81
+ - ".document"
82
+ - ".gitignore"
83
+ - ".gitlab-ci.yml"
84
+ - ".release_me.yaml"
85
+ - ".rspec"
86
+ - ".rubocop.yml"
87
+ - ".rubocop_todo.yml"
88
+ - ".ruby-version"
89
89
  - CHANGELOG.md
90
90
  - DEVELOPMENT.md
91
91
  - Gemfile
@@ -142,17 +142,17 @@ require_paths:
142
142
  - lib
143
143
  required_ruby_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.0.14.1
155
+ rubygems_version: 2.6.11
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: A repl based debugger for the puppet language