puppet-repl 0.1.1 → 0.2.0

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: b9496d20d14a3fca24bfc9bc6d052e05e63a653b
4
- data.tar.gz: 1929ee4b440a14225194aff0078ab50b5b558840
3
+ metadata.gz: 395dca824498b20ef6c0c3fbcdbbd70f77e1b44f
4
+ data.tar.gz: a2695e31bf0cdb543fff05c8437af71505ca75a6
5
5
  SHA512:
6
- metadata.gz: 78c385e129a628a5ab0944e857aafbf60b8874813c592fcedf212ad29d974b11b18b9504ff20e3f297a576d8865b3aa7a9e84b2cae28a11c2bb41781aab645e8
7
- data.tar.gz: 21f956516bb34e08a76388cc7d1fb07ca0daa3e461054ae54113cdca4664a234d37edd0c7405589302ff06eb4e141bdd184bc196c34bba2ff844dc598dcf7b6b
6
+ metadata.gz: e69332b0167a1db4d32ad151eb6468e7463ec1ca8bb3deff7d1698226924b665169d52a0fc7add5ff2a38385f2f3dc2264e3a2099b3513d23949f3f05f174d49
7
+ data.tar.gz: 05259e58f876fdc50a83711adf9cf7e2c57f0941b41610130a2d89e2be247074a58ff5b33cd70c629caf565756a56b162c3c622a0efdf3eca7ce923be95fef2f
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format documentation
data/.travis.yml CHANGED
@@ -2,11 +2,12 @@ language: ruby
2
2
  cache: bundler
3
3
  install: "bundle install --without development"
4
4
  before_script: "bundle exec puppet module install puppetlabs-stdlib"
5
- script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
5
+ script: "bundle exec rspec"
6
6
  rvm:
7
7
  - 1.9.3
8
8
  - 2.0.0
9
9
  - 2.2.1
10
+ - 2.1.3
10
11
  env:
11
12
  matrix:
12
13
  - PUPPET_GEM_VERSION="~> 3.8"
@@ -20,3 +21,9 @@ matrix:
20
21
  exclude:
21
22
  - rvm: 2.2.1
22
23
  env: PUPPET_GEM_VERSION="~> 3.8"
24
+ - rvm: 1.9.3
25
+ env: PUPPET_GEM_VERSION="~> 4.4"
26
+ - rvm: 1.9.3
27
+ env: PUPPET_GEM_VERSION="~> 4.3"
28
+ - rvm: 1.9.3
29
+ env: PUPPET_GEM_VERSION="~> 4.2"
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
+ ## 0.2.0
2
+ * Fixes #19 - lock down dependency versions
3
+ * fixes #18 - add ability to filter out functions based on namespace
4
+ * fixes #15 - node classes return error
5
+ * fixes #16 - use auto complete on functions and variables
6
+ * Fixes #14 - add functionality to set node object from remote source
7
+ * fixes other minor bugs found along the way
8
+ * adds ability to list classification parameters from ENC
9
+ ## 0.1.1
10
+ * adds ability to load files or urls
11
+ ## 0.1.0
12
+ * ensure the title of classes contains quotes
13
+ * adds support to import a file or import from stdin
14
+ * added additional ap support for puppet::pops::types
15
+ * adds ability to print resources and classes
16
+ * adds the ability to pass in a scope
1
17
  ## 0.0.8
2
18
  * adds ability to list currently loaded classes
3
- * adds formatted output using awesome print
19
+ * adds formatted output using awesome print
4
20
  * adds verbose type output when creating resources
5
21
  ## 0.0.7
6
22
  * Added ability to list scope variables
data/Gemfile CHANGED
@@ -1,18 +1,16 @@
1
1
  source "http://rubygems.org"
2
2
  gem 'puppet', ENV['PUPPET_GEM_VERSION'] || ">= 3.8"
3
- gem 'facterdb'
4
- gem 'awesome_print'
5
-
3
+ gem 'facterdb', "~> 0.3"
4
+ gem 'awesome_print', "~> 1.6"
6
5
  group :test do
7
6
  gem "rspec"
8
- gem 'rspec-puppet'
9
7
  gem "bundler"
10
8
  gem "jeweler", "~> 2.0.1"
11
9
  gem "simplecov", ">= 0"
12
10
  gem 'rake'
11
+ gem 'pry'
13
12
  end
14
13
 
15
14
  group :development do
16
- gem 'pry'
17
15
  gem "rdoc", "~> 3.12"
18
16
  end
data/Gemfile.lock CHANGED
@@ -5,20 +5,19 @@ GEM
5
5
  addressable (2.4.0)
6
6
  awesome_print (1.6.1)
7
7
  builder (3.2.2)
8
- coderay (1.1.0)
8
+ coderay (1.1.1)
9
9
  descendants_tracker (0.0.4)
10
10
  thread_safe (~> 0.3, >= 0.3.1)
11
11
  diff-lcs (1.2.5)
12
12
  docile (1.1.5)
13
13
  facter (2.4.6)
14
14
  CFPropertyList (~> 2.2.6)
15
- facterdb (0.3.1)
15
+ facterdb (0.3.5)
16
16
  facter
17
17
  jgrep
18
- json
19
18
  faraday (0.9.2)
20
19
  multipart-post (>= 1.2, < 3)
21
- git (1.2.9.1)
20
+ git (1.3.0)
22
21
  github_api (0.13.1)
23
22
  addressable (~> 2.4.0)
24
23
  descendants_tracker (~> 0.0.4)
@@ -26,8 +25,8 @@ GEM
26
25
  hashie (>= 3.4)
27
26
  multi_json (>= 1.7.5, < 2.0)
28
27
  oauth2
29
- hashie (3.4.3)
30
- hiera (1.3.4)
28
+ hashie (3.4.4)
29
+ hiera (3.1.2)
31
30
  json_pure
32
31
  highline (1.7.8)
33
32
  jeweler (2.0.1)
@@ -39,14 +38,14 @@ GEM
39
38
  nokogiri (>= 1.5.10)
40
39
  rake
41
40
  rdoc
42
- jgrep (1.4.0)
41
+ jgrep (1.4.1)
43
42
  json
44
43
  json (1.8.3)
45
44
  json_pure (1.8.3)
46
45
  jwt (1.5.1)
47
46
  method_source (0.8.2)
48
47
  mini_portile2 (2.0.0)
49
- multi_json (1.11.2)
48
+ multi_json (1.12.0)
50
49
  multi_xml (0.5.5)
51
50
  multipart-post (2.0.0)
52
51
  nokogiri (1.6.7.2)
@@ -61,19 +60,20 @@ GEM
61
60
  coderay (~> 1.1.0)
62
61
  method_source (~> 0.8.1)
63
62
  slop (~> 3.4)
64
- puppet (3.8.5)
65
- facter (> 1.6, < 3)
66
- hiera (~> 1.0)
63
+ puppet (4.4.2)
64
+ CFPropertyList (~> 2.2.6)
65
+ facter (> 2.0, < 4)
66
+ hiera (>= 2.0, < 4)
67
67
  json_pure
68
68
  rack (1.6.4)
69
- rake (10.5.0)
69
+ rake (11.1.2)
70
70
  rdoc (3.12.2)
71
71
  json (~> 1.4)
72
72
  rspec (3.4.0)
73
73
  rspec-core (~> 3.4.0)
74
74
  rspec-expectations (~> 3.4.0)
75
75
  rspec-mocks (~> 3.4.0)
76
- rspec-core (3.4.3)
76
+ rspec-core (3.4.4)
77
77
  rspec-support (~> 3.4.0)
78
78
  rspec-expectations (3.4.0)
79
79
  diff-lcs (>= 1.2.0, < 2.0)
@@ -81,8 +81,6 @@ GEM
81
81
  rspec-mocks (3.4.1)
82
82
  diff-lcs (>= 1.2.0, < 2.0)
83
83
  rspec-support (~> 3.4.0)
84
- rspec-puppet (2.4.0)
85
- rspec
86
84
  rspec-support (3.4.1)
87
85
  simplecov (0.11.2)
88
86
  docile (~> 1.1.0)
@@ -96,17 +94,16 @@ PLATFORMS
96
94
  ruby
97
95
 
98
96
  DEPENDENCIES
99
- awesome_print
97
+ awesome_print (~> 1.6)
100
98
  bundler
101
- facterdb
99
+ facterdb (~> 0.3)
102
100
  jeweler (~> 2.0.1)
103
101
  pry
104
102
  puppet (>= 3.8)
105
103
  rake
106
104
  rdoc (~> 3.12)
107
105
  rspec
108
- rspec-puppet
109
106
  simplecov
110
107
 
111
108
  BUNDLED WITH
112
- 1.11.2
109
+ 1.12.3
data/README.md CHANGED
@@ -4,21 +4,30 @@
4
4
 
5
5
  - [puppet-repl](#puppet-repl)
6
6
  - [Compatibility](#compatibility)
7
+ - [Production usage](#production-usage)
7
8
  - [Installation](#installation)
8
9
  - [Load path](#load-path)
10
+ - [Interactive demo](#interactive-demo)
11
+ - [Web demo](#web-demo)
9
12
  - [Usage](#usage)
10
13
  - [Using Variables](#using-variables)
11
14
  - [Listing variables](#listing-variables)
15
+ - [Listing functions](#listing-functions)
12
16
  - [Using functions](#using-functions)
13
17
  - [Duplicate resource error](#duplicate-resource-error)
14
18
  - [Setting the puppet log level](#setting-the-puppet-log-level)
19
+ - [Remote nodes](#remote-nodes)
20
+ - [Setup](#setup)
21
+ - [Usage](#usage-1)
22
+ - [Command line:](#command-line)
23
+ - [From repl session:](#from-repl-session)
24
+ - [Auto Complete](#auto-complete)
25
+ - [Playback support](#playback-support)
15
26
  - [Troubleshooting](#troubleshooting)
16
- - [Forward](#forward)
17
27
  - [Copyright](#copyright)
18
28
 
19
29
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
20
-
21
- [![Build Status](https://travis-ci.org/nwops/puppet-repl.png)](https://travis-ci.org/nwops/puppet-repl)[![Gem Version](https://badge.fury.io/rb/puppet-repl.svg)](https://badge.fury.io/rb/puppet-repl)
30
+ [![BuildStatus](https://travis-ci.org/nwops/puppet-repl.svg?branch=master)](https://travis-ci.org/nwops/puppet-repl?branch=master)[![Gem Version](https://badge.fury.io/rb/puppet-repl.svg)](https://badge.fury.io/rb/puppet-repl)
22
31
  # puppet-repl
23
32
 
24
33
  A interactive command line tool for evaluating the puppet language.
@@ -42,10 +51,14 @@ in the repl.
42
51
  ## Interactive demo
43
52
  I have put together a repo with a few setup instructions that will assist you in setting up a "mock" environment
44
53
  for usage with the puppet-repl. This was originally intended when giving a demo of the repl, but also seems
45
- useful for other people.
54
+ useful for other people.
46
55
 
47
56
  https://github.com/nwops/puppet-repl-demo
48
57
 
58
+ ## Web demo
59
+ There is a web version of the [puppet-repl](https://www.puppet-repl.com) online but is somewhat
60
+ limited at this time. In the future we will be adding lots of awesome features to the web repl.
61
+
49
62
  ## Usage
50
63
  Puppet-repl will only parse and evaulate your code. It will not build a catalog
51
64
  and try to enforce the catalog. This has a few side affects.
@@ -112,36 +125,16 @@ Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more infor
112
125
  ### Listing variables
113
126
  To see the current variables in the scope use the `vars` keyword.
114
127
 
115
- ```
116
- >> $var1 = 'value'
117
- => value
118
- >> $var2 = {'key1' => 'value1'}
119
- => {"key1"=>"value1"}
120
- >> vars
121
- "Facts were removed for easier viewing"
122
- {
123
- "datacenter" => "datacenter1",
124
- "facts" => "removed by the puppet-repl",
125
- "module_name" => "",
126
- "name" => "main",
127
- "title" => "main",
128
- "trusted" => {
129
- "authenticated" => "local",
130
- "certname" => nil,
131
- "domain" => nil,
132
- "extensions" => {},
133
- "hostname" => nil
134
- },
135
- "var1" => "value",
136
- "var2" => {
137
- "key1" => "value1"
138
- }
139
- }
128
+ ![variables](resources/variables.png)
129
+
130
+ ## Listing functions
131
+ Knowing what functions are available and where they come from is extremely helpful especially in a repl session. Run the `functions` keyword to get a name spaced list of functions. You can further filter out functions by passing in a filter argument. `functions stdlib`
132
+
133
+ ![functions](resources/functions.png)
140
134
 
141
- ```
142
135
  ## Using functions
143
136
  Functions will run and produce the desired output. If you type the word `functions`
144
- a list of available functions will be displayed on the screen.
137
+ a list of available functions will be displayed on the screen along with a namespace to help you identify where they came from.
145
138
 
146
139
  ```
147
140
  >> split('hello/there/one/two/three','/')
@@ -166,22 +159,80 @@ If you want to see what puppet is doing behind the scenes you can set the log le
166
159
  via `:set loglevel debug`. Valid log levels are `debug`, `info`, `warning` and other
167
160
  levels defined in puppet [config reference](https://docs.puppetlabs.com/puppet/4.4/reference/configuration.html#loglevel) .
168
161
 
169
- ```
170
- >> hiera('value')
171
- => foo
172
- >> :set loglevel debug
173
- loglevel debug is set
174
- >> hiera('value')
175
- Debug: hiera(): Looking up value in YAML backend
176
- Debug: hiera(): Looking for data source nodes/foo.example.com
177
- Debug: hiera(): Found value in nodes/foo.example.com
178
- => foo
179
- ```
162
+ ![hiera](resources/hiera.png)
163
+
164
+ ## Remote nodes
165
+ This is new for 0.2.0. The puppet-repl now has the ability to pull in remote node information. Instead of mocking facts you can pull in real information! Get real facts and real node classification from the puppet master and then play with the info in the repl session. This is made possible by using the puppet node indirector interface.
166
+
167
+ ie. `puppet node find hostname --terminus rest --render-as yaml`
168
+
169
+ In order to use this feature you will need to setup a few things.
170
+
171
+ ### Setup
172
+ 1. Allow node rest calls to your workstation on the puppet master(s)
173
+ See https://github.com/nwops/puppet-repl/issues/17 for more info on allowing this rule.
174
+
175
+ 2. Ensure you have the same code that your puppet master does. Since this pulls in classification you will need to have all the puppet modules defined in your
176
+ environmentpath or basemodulepath. The simple thing to do is to point your basemodulepath to your fixtures directory if using rspec-puppet or some other high level modules directory. For PE users you will want to ensure you have all the
177
+ pe specific modules in your development environment. Not doing this step will result in class not found errors.
178
+
179
+ 3. Set the server config in your local puppet.conf. (on your development machine)
180
+
181
+ a. Find your puppet config file `puppet config print config`
182
+
183
+ b. edit the config file with an editor
184
+
185
+ c. add `server = <hostname>` to your main block
186
+
187
+ 4. If using hiera you also need to set the path to your hiera config file since
188
+ the puppet-repl will be compiling puppet code which could in turn call hiera
189
+ functions. Additionally, make sure your hiera config points to the correct
190
+ data location.
191
+
192
+ ```
193
+ [main]
194
+ server = pe-puppet.localdomain
195
+ basemodulepath = /Users/cosman/github/puppet-repl-demo/modules:/Users/cosman/Downloads/pe_modules
196
+ hiera_config = /Users/cosman/github/puppet-repl-demo/hieradata/hiera.yaml
197
+
198
+
199
+ ```
200
+
201
+
202
+ ### Usage
203
+ There are two ways of using the remote node feature. You can either
204
+ pass in the node name from the command line or set the node name from the repl session.
205
+
206
+ #### Command line:
207
+ `prepl -n node_name`
208
+
209
+ ![command line](resources/command_line_node.png)
210
+
211
+ #### From repl session:
212
+ `:set node node_name`
213
+
214
+ ![command line](resources/set_node.png)
215
+
216
+
217
+ This is also extremely useful to check classification rules and variables by your ENC. So instead of running your ENC script manually we get the puppet master to run this indirectly and return the results to you.
218
+
219
+ ## Auto Complete
220
+ The puppet-repl uses readline internally. So any variable or function is also available for auto completion.
221
+ Press the tab key to engage the auto complete functionality.
222
+
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. Support for this functionality is extremely limited due to #2. However, if you list things on a single line
225
+ you "could" overcome this limitation.
226
+
227
+ `play https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw`
228
+
229
+ or
230
+
231
+ `prepl -p https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw`
232
+
180
233
  ## Troubleshooting
234
+ Please file an issue so we can track bugs.
181
235
 
182
- ## Forward
183
- I was just playing around and created this simple tool. Its beta quality,
184
- and a ton of features need to be added. Please create a issue if you see a bug or feature that should be added.
185
236
 
186
237
  Pull requests welcomed.
187
238
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -9,11 +9,12 @@ module AwesomePrint
9
9
  # about printing different puppet objects
10
10
  def cast_with_puppet_resource(object, type)
11
11
  cast = cast_without_puppet_resource(object, type)
12
- if (defined?(::Puppet::Type)) && (object.is_a?(::Puppet::Type))
12
+ # check the object to see if it has an acestor (< ) of the specified type
13
+ if (defined?(::Puppet::Type)) && (object.class < ::Puppet::Type)
13
14
  cast = :puppet_type
14
- elsif (defined?(::Puppet::Pops::Types)) && (object.is_a?(::Puppet::Pops::Types))
15
- cast = :puppet_type
16
- elsif (defined?(::Puppet::Parser::Resource)) && (object.is_a?(::Puppet::Parser::Resource))
15
+ elsif (defined?(::Puppet::Pops::Types)) && (object.class < ::Puppet::Pops::Types)
16
+ cast = :puppet_type
17
+ elsif (defined?(::Puppet::Parser::Resource)) && (object.class < ::Puppet::Parser::Resource)
17
18
  cast = :puppet_resource
18
19
  end
19
20
  cast
@@ -7,33 +7,68 @@ module PuppetRepl
7
7
  class Cli
8
8
  include PuppetRepl::Support
9
9
 
10
- attr_accessor :settings, :log_level
10
+ attr_accessor :settings, :log_level, :in_buffer, :out_buffer, :html_mode
11
11
 
12
- def initialize
12
+ def initialize(options={})
13
13
  @log_level = 'notice'
14
+ @out_buffer = options[:out_buffer] || $stdout
15
+ @html_mode = options[:html_mode] || false
16
+ @in_buffer = options[:in_buffer] || $stdin
17
+ comp = Proc.new do |s|
18
+ key_words.grep(/^#{Regexp.escape(s)}/)
19
+ end
20
+ Readline.completion_append_character = ""
21
+ Readline.basic_word_break_characters = " "
22
+
23
+ Readline.completion_proc = comp
24
+ AwesomePrint.defaults = {
25
+ :html => @html_mode,
26
+ :sort_keys => true,
27
+ :indent => 2
28
+ }
29
+ do_initialize
14
30
  end
15
31
 
16
- def ap_formatter
17
- unless @ap_formatter
18
- inspector = AwesomePrint::Inspector.new({:sort_keys => true, :indent => 2})
19
- @ap_formatter = AwesomePrint::Formatter.new(inspector)
20
- end
21
- @ap_formatter
32
+ # returns a cached list of key words
33
+ def key_words
34
+ # because dollar signs don't work we can't display a $ sign in the keyword
35
+ # list so its not explicitly clear what the keyword
36
+ variables = scope.to_hash.keys
37
+ # prepend a :: to topscope variables
38
+ scoped_vars = variables.map { |k,v| scope.compiler.topscope.exist?(k) ? "$::#{k}" : "$#{k}" }
39
+ # append a () to functions so we know they are functions
40
+ funcs = function_map.keys.map { |k| "#{k.split('::').last}()"}
41
+ (scoped_vars + funcs + static_responder_list).uniq.sort
22
42
  end
23
43
 
24
44
  def puppet_eval(input)
25
45
  parser.evaluate_string(scope, input)
26
46
  end
27
47
 
48
+ # looks up the type in the catalog by using the type and title
49
+ # and returns the resource in ral format
28
50
  def to_resource_declaration(type)
29
- res = scope.catalog.resource(type.type_name, type.title)
30
- res.to_ral
51
+ if type.respond_to?(:type_name) and type.respond_to?(:title)
52
+ title = type.title
53
+ type_name = type.type_name
54
+ else
55
+ # not all types have a type_name and title so we
56
+ # output to a string and parse the results
57
+ type_result = /(\w+)\['?(\w+)'?\]/.match(type.to_s)
58
+ title = type_result[2]
59
+ type_name = type_result[1]
60
+ end
61
+ res = scope.catalog.resource(type_name, title)
62
+ if res
63
+ return res.to_ral
64
+ end
65
+ # don't return anything or returns nil if item is not in the catalog
31
66
  end
32
67
 
33
68
  # ruturns a formatted array
34
69
  def expand_resource_type(types)
35
70
  output = [types].flatten.map do |t|
36
- if t.class.to_s == 'Puppet::Pops::Types::PResourceType'
71
+ if t.class.to_s =~ /Puppet::Pops::Types/
37
72
  to_resource_declaration(t)
38
73
  else
39
74
  t
@@ -49,82 +84,77 @@ module PuppetRepl
49
84
  return output.first
50
85
  end
51
86
  return output
52
- elsif result.instance_of?(Puppet::Pops::Types::PResourceType)
87
+ elsif result.class.to_s =~ /Puppet::Pops::Types/
53
88
  return to_resource_declaration(result)
54
89
  end
55
90
  result
56
91
  end
57
92
 
58
- def set_log_level(level)
59
- Puppet::Util::Log.level = level.to_sym
60
- Puppet::Util::Log.newdestination(:console)
61
- end
62
-
63
- def handle_set(input)
64
- args = input.split(' ')
65
- args.shift # throw away the set
66
- case args.shift
67
- when /loglevel/
68
- if level = args.shift
69
- @log_level = level
70
- set_log_level(level)
71
- puts "loglevel #{Puppet::Util::Log.level} is set"
72
- end
73
- end
74
- end
75
-
76
- def handle_input(input)
77
- case input
78
- when /^play|^facts|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/
79
- args = input.split(' ')
80
- command = args.shift.to_sym
81
- if self.respond_to?(command)
82
- self.send(command, args)
83
- end
84
- when /exit/
85
- exit 0
86
- when /^:set/
87
- handle_set(input)
88
- when '_'
89
- puts(" => #{@last_item}")
90
- else
93
+ def handle_input(input_text)
94
+ input_text.split("\n").each do |input|
91
95
  begin
92
- result = puppet_eval(input)
93
- @last_item = result
94
- print " => "
95
- output = normalize_output(result)
96
- if output.nil?
97
- puts ""
96
+ output = ''
97
+ case input
98
+ when /^play|^classification|^facts|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/
99
+ args = input.split(' ')
100
+ command = args.shift.to_sym
101
+ if self.respond_to?(command)
102
+ output = self.send(command, args)
103
+ end
104
+ return out_buffer.puts output
105
+ when /exit/
106
+ exit 0
107
+ when /^:set/
108
+ output = handle_set(input)
109
+ when '_'
110
+ output = " => #{@last_item}"
98
111
  else
99
- ap(output)
112
+ result = puppet_eval(input)
113
+ @last_item = result
114
+ output = normalize_output(result)
115
+ if output.nil?
116
+ output = ""
117
+ else
118
+ output = output.ai
119
+ end
100
120
  end
121
+ rescue LoadError => e
122
+ output = e.message.fatal
123
+ rescue Errno::ETIMEDOUT => e
124
+ output = e.message.fatal
101
125
  rescue ArgumentError => e
102
- print " => "
103
- puts e.message.fatal
126
+ output = e.message.fatal
104
127
  rescue Puppet::ResourceError => e
105
- print " => "
106
- puts e.message.fatal
128
+ output = e.message.fatal
107
129
  rescue Puppet::ParseErrorWithIssue => e
108
- print " => "
109
- puts e.message.fatal
110
- rescue Exception => e
111
- puts e.message.fatal
130
+ output = e.message.fatal
131
+ rescue PuppetRepl::Exception::FatalError => e
132
+ output = e.message.fatal
133
+ out_buffer.puts output
134
+ exit 1
135
+ rescue PuppetRepl::Exception::Error => e
136
+ output = e.message.fatal
112
137
  end
138
+ out_buffer.print " => "
139
+ out_buffer.puts output
113
140
  end
114
141
  end
115
142
 
116
143
  def self.print_repl_desc
117
- puts(<<-EOT)
144
+ output = <<-EOT
118
145
  Ruby Version: #{RUBY_VERSION}
119
146
  Puppet Version: #{Puppet.version}
120
147
  Puppet Repl Version: #{PuppetRepl::VERSION}
121
148
  Created by: NWOps <corey@nwops.io>
122
149
  Type "exit", "functions", "vars", "krt", "facts", "resources", "classes",
123
- "play","reset", or "help" for more information.
150
+ "play", "classification", "reset", or "help" for more information.
124
151
 
125
152
  EOT
153
+ output
126
154
  end
127
155
 
156
+ # reads input from stdin, since readline requires a tty
157
+ # we cannot read from other sources as readline requires a file object
128
158
  def read_loop
129
159
  while buf = Readline.readline(">> ", true)
130
160
  handle_input(buf)
@@ -138,11 +168,13 @@ Type "exit", "functions", "vars", "krt", "facts", "resources", "classes",
138
168
  def self.start(options={:scope => nil})
139
169
  opts = Trollop::options do
140
170
  opt :play, "Url or file to load from", :required => false, :type => String
141
- opt :run_once, "Evaulate and quit", :required => false, :default => false
171
+ opt :run_once, "Evaluate and quit", :required => false, :default => false
172
+ opt :node_name, "Remote Node to grab facts from", :required => false, :type => String
142
173
  end
143
174
  options = opts.merge(options)
144
- print_repl_desc
175
+ puts print_repl_desc
145
176
  repl_obj = new
177
+ repl_obj.remote_node_name = opts[:node_name] if opts[:node_name]
146
178
  repl_obj.initialize_from_scope(options[:scope])
147
179
  if options[:play]
148
180
  repl_obj.play_back(opts)
@@ -4,15 +4,15 @@ module PuppetRepl
4
4
  # creates a puppet environment given a module path and environment name
5
5
  # this is cached
6
6
  def puppet_environment
7
- unless @puppet_environment
8
- do_initialize
9
- @puppet_environment = Puppet::Node::Environment.create(
7
+ @puppet_environment ||= create_environment
8
+ end
9
+
10
+ def create_environment
11
+ @puppet_environment = Puppet::Node::Environment.create(
10
12
  default_puppet_env_name,
11
13
  default_modules_paths,
12
14
  default_manifests_dir
13
- )
14
- end
15
- @puppet_environment
15
+ )
16
16
  end
17
17
 
18
18
  def set_environment(value)