puppet-repl 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +17 -2
- data/VERSION +1 -1
- data/lib/puppet-repl/cli.rb +13 -7
- data/lib/puppet-repl/support/input_responders.rb +1 -0
- data/lib/puppet-repl/support/play.rb +29 -2
- data/lib/puppet-repl/support.rb +4 -0
- data/lib/version.rb +1 -1
- data/puppet-repl.gemspec +3 -3
- data/spec/prepl_spec.rb +6 -1
- data/spec/puppet-repl_spec.rb +11 -7
- data/spec/support_spec.rb +10 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8322d7d0831649ede23894dc08e9135fadc252cd
|
4
|
+
data.tar.gz: d910d7246982ffb04f5f0dda6a64a7408ab035c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa51e79914d8b315c07572c50ba52cd88c38edf6ab2e17bada681e8e42cc2537d557774dbeeaab8e58a7d3a62e8ffef2878eb34de431b5b59dd42d830688ab78
|
7
|
+
data.tar.gz: 4da905e6ad4e7201a329bb661544bec8a44d98c5c6cee488ea9e488e3850f2eebddca1478f493e9cb0bdceed7a4eff8f7a753283ddd5e2a6f9e9bfa23e0b54de
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -221,8 +221,8 @@ The puppet-repl uses readline internally. So any variable or function is also a
|
|
221
221
|
Press the tab key to engage the auto complete functionality.
|
222
222
|
|
223
223
|
## Playback support
|
224
|
-
Puppet-repl now supports playing back files or urls and loading the content into the repl session. This means if you want to start a repl session from an existing file or url you can play the content back in the repl.
|
225
|
-
|
224
|
+
Puppet-repl now supports playing back files or urls and loading the content into the repl session. This means if you want to start a repl session from an existing file or url you can play the content back in the repl.
|
225
|
+
You can also playback a file that contains puppet code and repl commands.
|
226
226
|
|
227
227
|
`play https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw`
|
228
228
|
|
@@ -230,6 +230,21 @@ or
|
|
230
230
|
|
231
231
|
`prepl -p https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw`
|
232
232
|
|
233
|
+
|
234
|
+
### Web based playback support
|
235
|
+
If using the [web based repl](https://www.puppet-repl.com) you can playback a shared url
|
236
|
+
which would start a repl session and then load the content from the url or parameter.
|
237
|
+
|
238
|
+
Example:
|
239
|
+
https://www.puppet-repl.com/play?url=https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0
|
240
|
+
|
241
|
+
or for single commands
|
242
|
+
|
243
|
+
https://www.puppet-repl.com/play?content=vars
|
244
|
+
|
245
|
+
Please note the web based repl only contains a minimal amount of puppet modules. So its likely
|
246
|
+
that your code may not work if using third party modules. This may change in the future though.
|
247
|
+
|
233
248
|
## Troubleshooting
|
234
249
|
Please file an issue so we can track bugs.
|
235
250
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/puppet-repl/cli.rb
CHANGED
@@ -90,8 +90,10 @@ module PuppetRepl
|
|
90
90
|
result
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
# this method handles all input and expects a string of text.
|
94
|
+
#
|
95
|
+
def handle_input(input)
|
96
|
+
raise ArgumentError unless input.instance_of?(String)
|
95
97
|
begin
|
96
98
|
output = ''
|
97
99
|
case input
|
@@ -135,9 +137,10 @@ module PuppetRepl
|
|
135
137
|
rescue PuppetRepl::Exception::Error => e
|
136
138
|
output = e.message.fatal
|
137
139
|
end
|
138
|
-
|
139
|
-
|
140
|
-
|
140
|
+
unless output.empty?
|
141
|
+
out_buffer.print " => "
|
142
|
+
out_buffer.puts output unless output.empty?
|
143
|
+
end
|
141
144
|
end
|
142
145
|
|
143
146
|
def self.print_repl_desc
|
@@ -174,9 +177,12 @@ Type "exit", "functions", "vars", "krt", "facts", "resources", "classes",
|
|
174
177
|
full_buffer = ''
|
175
178
|
while buf = Readline.readline("#{line_number}:>> ", true)
|
176
179
|
begin
|
177
|
-
line_number = line_number.next
|
178
180
|
full_buffer += buf
|
179
|
-
|
181
|
+
# unless this is puppet code, otherwise skip repl keywords
|
182
|
+
unless keyword_expression.match(buf)
|
183
|
+
line_number = line_number.next
|
184
|
+
parser.parse_string(full_buffer)
|
185
|
+
end
|
180
186
|
rescue Puppet::ParseErrorWithIssue => e
|
181
187
|
if multiline_input?(e)
|
182
188
|
out_buffer.print ' '
|
@@ -38,20 +38,47 @@ module PuppetRepl
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# opens the url and reads the data
|
42
|
+
def fetch_url_data(url)
|
43
|
+
open(url).read
|
44
|
+
end
|
45
|
+
|
41
46
|
def play_back_url(url)
|
42
47
|
begin
|
43
48
|
require 'open-uri'
|
44
49
|
require 'net/http'
|
45
50
|
converted_url = convert_to_text(url)
|
46
|
-
str =
|
51
|
+
str = fetch_url_data(converted_url)
|
47
52
|
play_back_string(str)
|
48
53
|
rescue SocketError
|
49
54
|
abort "puppet-repl can't play `#{converted_url}'"
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
58
|
+
# plays back the string to the output stream
|
59
|
+
# puts the input to the output as well as the produced output
|
53
60
|
def play_back_string(str)
|
54
|
-
|
61
|
+
full_buffer = ''
|
62
|
+
str.split("\n").each do |buf|
|
63
|
+
begin
|
64
|
+
full_buffer += buf
|
65
|
+
# unless this is puppet code, otherwise skip repl keywords
|
66
|
+
if keyword_expression.match(buf)
|
67
|
+
out_buffer.write(">> ")
|
68
|
+
else
|
69
|
+
parser.parse_string(full_buffer)
|
70
|
+
out_buffer.write(">> ")
|
71
|
+
end
|
72
|
+
rescue Puppet::ParseErrorWithIssue => e
|
73
|
+
if multiline_input?(e)
|
74
|
+
full_buffer += "\n"
|
75
|
+
next
|
76
|
+
end
|
77
|
+
end
|
78
|
+
out_buffer.puts(full_buffer)
|
79
|
+
handle_input(full_buffer)
|
80
|
+
full_buffer = ''
|
81
|
+
end
|
55
82
|
end
|
56
83
|
end
|
57
84
|
end
|
data/lib/puppet-repl/support.rb
CHANGED
@@ -73,6 +73,10 @@ module PuppetRepl
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def keyword_expression
|
77
|
+
@keyword_expression ||= Regexp.new(/^exit|^:set|^play|^classification|^facts|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/)
|
78
|
+
end
|
79
|
+
|
76
80
|
def known_resource_types
|
77
81
|
res = {
|
78
82
|
:hostclasses => scope.known_resource_types.hostclasses.keys,
|
data/lib/version.rb
CHANGED
data/puppet-repl.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: puppet-repl 0.2.
|
5
|
+
# stub: puppet-repl 0.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "puppet-repl"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Corey Osman"]
|
14
|
-
s.date = "2016-05-
|
14
|
+
s.date = "2016-05-21"
|
15
15
|
s.description = "A interactive command line tool for evaluating the puppet language"
|
16
16
|
s.email = "corey@nwops.io"
|
17
17
|
s.executables = ["prepl"]
|
data/spec/prepl_spec.rb
CHANGED
@@ -5,6 +5,10 @@ describe 'prepl' do
|
|
5
5
|
File.join(fixtures_dir, 'sample_manifest.pp')
|
6
6
|
end
|
7
7
|
|
8
|
+
before(:each) do
|
9
|
+
allow(PuppetRepl).to receive(:fetch_url_data).with(file_url).and_return(File.read(fixtures_file))
|
10
|
+
end
|
11
|
+
|
8
12
|
let(:file_url) do
|
9
13
|
'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'
|
10
14
|
end
|
@@ -22,7 +26,8 @@ describe 'prepl' do
|
|
22
26
|
expect(`bundle exec bin/prepl --play #{fixtures_file} --run-once`)
|
23
27
|
.to match(/Puppet::Type::File/)
|
24
28
|
end
|
25
|
-
|
29
|
+
xit do
|
30
|
+
# this test does not work without internet, and I am at 30K feet right now
|
26
31
|
expect(`bundle exec bin/prepl --play #{file_url} --run-once`)
|
27
32
|
.to match(/Puppet::Type::File/)
|
28
33
|
end
|
data/spec/puppet-repl_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe "PuppetRepl" do
|
|
32
32
|
"$var1 = 'test'\nfile{\"/tmp/${var1}.txt\": ensure => present, mode => '0755'}\nvars"
|
33
33
|
end
|
34
34
|
it do
|
35
|
-
repl.
|
35
|
+
repl.play_back_string(input)
|
36
36
|
expect(output.string).to match(/server_facts/) if Puppet.version.to_f >= 4.1
|
37
37
|
expect(output.string).to match(/test/)
|
38
38
|
expect(output.string).to match(/Puppet::Type::File/)
|
@@ -43,8 +43,8 @@ describe "PuppetRepl" do
|
|
43
43
|
"$var1 = 'test'\n $var2 = 'test2'"
|
44
44
|
end
|
45
45
|
it do
|
46
|
-
repl.
|
47
|
-
expect(output.string).to eq("\n => \e[0;33m\"test\"\e[0m\n => \e[0;33m\"test2\"\e[0m\n")
|
46
|
+
repl.play_back_string(input)
|
47
|
+
expect(output.string).to eq("\n>> $var1 = 'test'\n => \e[0;33m\"test\"\e[0m\n>> $var2 = 'test2'\n => \e[0;33m\"test2\"\e[0m\n")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
describe '1 lines' do
|
@@ -52,8 +52,8 @@ describe "PuppetRepl" do
|
|
52
52
|
"$var1 = 'test'"
|
53
53
|
end
|
54
54
|
it do
|
55
|
-
repl.
|
56
|
-
expect(output.string).to eq("\n => \e[0;33m\"test\"\e[0m\n")
|
55
|
+
repl.play_back_string(input)
|
56
|
+
expect(output.string).to eq("\n>> $var1 = 'test'\n => \e[0;33m\"test\"\e[0m\n")
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -94,7 +94,7 @@ describe "PuppetRepl" do
|
|
94
94
|
" "
|
95
95
|
end
|
96
96
|
it 'can run' do
|
97
|
-
repl_output = "\n
|
97
|
+
repl_output = "\n"
|
98
98
|
repl.handle_input(input)
|
99
99
|
expect(output.string).to eq(repl_output)
|
100
100
|
end
|
@@ -117,6 +117,10 @@ describe "PuppetRepl" do
|
|
117
117
|
File.join(fixtures_dir, 'sample_manifest.pp')
|
118
118
|
end
|
119
119
|
|
120
|
+
before(:each) do
|
121
|
+
allow(repl).to receive(:fetch_url_data).with(file_url).and_return(File.read(fixtures_file))
|
122
|
+
end
|
123
|
+
|
120
124
|
let(:file_url) do
|
121
125
|
'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'
|
122
126
|
end
|
@@ -340,7 +344,7 @@ describe "PuppetRepl" do
|
|
340
344
|
end
|
341
345
|
|
342
346
|
describe 'unidentified object' do
|
343
|
-
let(:repl_output) { "\n
|
347
|
+
let(:repl_output) { "\n" }
|
344
348
|
describe "Node['foot']" do
|
345
349
|
let(:input) { subject }
|
346
350
|
it 'returns string' do
|
data/spec/support_spec.rb
CHANGED
@@ -16,20 +16,23 @@ describe 'support' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'play' do
|
19
|
-
|
20
|
-
|
19
|
+
before(:each) do
|
20
|
+
allow(repl).to receive(:fetch_url_data).with(file_url + ".txt").and_return(File.read(fixtures_file))
|
21
21
|
end
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
let(:fixtures_file) do
|
24
|
+
File.join(fixtures_dir, 'sample_manifest.pp')
|
24
25
|
end
|
25
26
|
|
26
|
-
let(:
|
27
|
-
''
|
27
|
+
let(:file_url) do
|
28
|
+
'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0'
|
29
|
+
end
|
30
|
+
let(:input) do
|
31
|
+
"play #{file_url}"
|
28
32
|
end
|
29
33
|
|
30
34
|
it do
|
31
35
|
repl.handle_input(input)
|
32
|
-
expect(output.string).to match(/server_facts/) if Puppet.version.to_f >= 4.1
|
33
36
|
expect(output.string).to match(/test/)
|
34
37
|
expect(output.string).to match(/Puppet::Type::File/)
|
35
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|