puppet-repl 0.1.0 → 0.1.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: 82f04618f457e0c269f510e98978755cad93858a
4
- data.tar.gz: 354e81a9f221f4ae4752255b2dac80f9d49ea4d7
3
+ metadata.gz: b9496d20d14a3fca24bfc9bc6d052e05e63a653b
4
+ data.tar.gz: 1929ee4b440a14225194aff0078ab50b5b558840
5
5
  SHA512:
6
- metadata.gz: 0b92c9c4be02ec0a64ae0b2a06f5fea0d69ef10207ee671597fddc76a6e0c94804571afbb477953330288a588aac3b91e29757baf7b46c592f8fbfc1f635f4a7
7
- data.tar.gz: 82c321a30737266061664ad3e0d2d4b3a5c9ba66a7c6e882c7dfe61df2fac4ba3f9b9eb07b12c74827f1cdeda54ba6042f476d26a19e7e3e975e172cbee0e5b4
6
+ metadata.gz: 78c385e129a628a5ab0944e857aafbf60b8874813c592fcedf212ad29d974b11b18b9504ff20e3f297a576d8865b3aa7a9e84b2cae28a11c2bb41781aab645e8
7
+ data.tar.gz: 21f956516bb34e08a76388cc7d1fb07ca0daa3e461054ae54113cdca4664a234d37edd0c7405589302ff06eb4e141bdd184bc196c34bba2ff844dc598dcf7b6b
data/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
20
20
 
21
- [![Build Status](https://travis-ci.org/nwops/puppet-repl.png)](https://travis-ci.org/nwops/puppet-repl)
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)
22
22
  # puppet-repl
23
23
 
24
24
  A interactive command line tool for evaluating the puppet language.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/prepl CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require_relative '../lib/puppet-repl'
4
3
 
5
4
  PuppetRepl::Cli.start
data/lib/puppet-repl.rb CHANGED
@@ -2,7 +2,7 @@ require_relative 'puppet-repl/cli'
2
2
  require_relative 'version'
3
3
  require 'awesome_print'
4
4
  require_relative 'awesome_print/ext/awesome_puppet'
5
-
5
+ require_relative 'trollop'
6
6
  # monkey patch in some color effects string methods
7
7
  class String
8
8
  def red; "\033[31m#{self}\033[0m" end
@@ -74,43 +74,41 @@ module PuppetRepl
74
74
  end
75
75
 
76
76
  def handle_input(input)
77
- return if input.nil? or input.empty?
78
- args = input.split(' ')
79
- return if args.count < 1
80
- command = args.shift.to_sym
81
- if self.respond_to?(command)
82
- self.send(command, args)
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}")
83
90
  else
84
- case input
85
- when /exit/
86
- exit 0
87
- when /^:set/
88
- handle_set(input)
89
- when '_'
90
- puts(" => #{@last_item}")
91
- else
92
- begin
93
- result = puppet_eval(input)
94
- @last_item = result
95
- print " => "
96
- output = normalize_output(result)
97
- if output.nil?
98
- puts ""
99
- else
100
- ap(output)
101
- end
102
- rescue ArgumentError => e
103
- print " => "
104
- puts e.message.fatal
105
- rescue Puppet::ResourceError => e
106
- print " => "
107
- puts e.message.fatal
108
- rescue Puppet::ParseErrorWithIssue => e
109
- print " => "
110
- puts e.message.fatal
111
- rescue Exception => e
112
- puts e.message.fatal
91
+ begin
92
+ result = puppet_eval(input)
93
+ @last_item = result
94
+ print " => "
95
+ output = normalize_output(result)
96
+ if output.nil?
97
+ puts ""
98
+ else
99
+ ap(output)
113
100
  end
101
+ rescue ArgumentError => e
102
+ print " => "
103
+ puts e.message.fatal
104
+ rescue Puppet::ResourceError => e
105
+ print " => "
106
+ puts e.message.fatal
107
+ rescue Puppet::ParseErrorWithIssue => e
108
+ print " => "
109
+ puts e.message.fatal
110
+ rescue Exception => e
111
+ puts e.message.fatal
114
112
  end
115
113
  end
116
114
  end
@@ -122,7 +120,7 @@ Puppet Version: #{Puppet.version}
122
120
  Puppet Repl Version: #{PuppetRepl::VERSION}
123
121
  Created by: NWOps <corey@nwops.io>
124
122
  Type "exit", "functions", "vars", "krt", "facts", "resources", "classes",
125
- "reset", or "help" for more information.
123
+ "play","reset", or "help" for more information.
126
124
 
127
125
  EOT
128
126
  end
@@ -138,15 +136,29 @@ Type "exit", "functions", "vars", "krt", "facts", "resources", "classes",
138
136
  # if from a file, the repl will process the file and continue to prompt
139
137
  # @param [Scope] puppet scope object
140
138
  def self.start(options={:scope => nil})
139
+ opts = Trollop::options do
140
+ opt :play, "Url or file to load from", :required => false, :type => String
141
+ opt :run_once, "Evaulate and quit", :required => false, :default => false
142
+ end
143
+ options = opts.merge(options)
141
144
  print_repl_desc
142
145
  repl_obj = new
143
- if ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?)
144
- input = ARGF.first
145
- repl_obj.handle_input(input)
146
- exit 0
147
- end
148
146
  repl_obj.initialize_from_scope(options[:scope])
149
- repl_obj.read_loop
147
+ if options[:play]
148
+ repl_obj.play_back(opts)
149
+ # when the user supplied a file name without using the args (stdin)
150
+ elsif ARGF.filename != "-"
151
+ path = File.expand_path(ARGF.filename)
152
+ repl_obj.play_back(:play => path)
153
+ # when the user supplied a file content using stdin, aka. cat,pipe,echo or redirection
154
+ elsif ARGF.filename == "-" and (not STDIN.tty? and not STDIN.closed?)
155
+ input = ARGF.read
156
+ repl_obj.handle_input(input)
157
+ end
158
+ # helper code to make tests exit the loop
159
+ unless options[:run_once]
160
+ repl_obj.read_loop
161
+ end
150
162
  end
151
163
  end
152
164
  end
@@ -46,7 +46,7 @@ module PuppetRepl
46
46
 
47
47
  def resources(args=[])
48
48
  res = scope.compiler.catalog.resources.map do |res|
49
- res.to_s
49
+ res.to_s.gsub(/\[/, "['").gsub(/\]/, "']") # ensure the title has quotes
50
50
  end
51
51
  if !args.first.nil?
52
52
  ap res[args.first.to_i]
@@ -12,7 +12,6 @@ module PuppetRepl
12
12
  puts "puppet-repl can't play #{config[:play]}'"
13
13
  end
14
14
  end
15
- read_loop
16
15
  end
17
16
 
18
17
  def play_back_url(url)
@@ -24,7 +23,7 @@ module PuppetRepl
24
23
  elsif url[/github.com.*blob/]
25
24
  url.sub!('blob', 'raw')
26
25
  end
27
- play_back_string open(url).string
26
+ play_back_string open(url).read
28
27
  rescue SocketError
29
28
  abort "puppet-repl can't play `#{url}'"
30
29
  end
data/lib/trollop.rb ADDED
@@ -0,0 +1,861 @@
1
+ # lib/trollop.rb -- trollop command-line processing library
2
+ # Copyright (c) 2008-2014 William Morgan.
3
+ # Copyright (c) 2014 Red Hat, Inc.
4
+ # trollop is licensed under the MIT license.
5
+
6
+ require 'date'
7
+
8
+ module Trollop
9
+ # note: this is duplicated in gemspec
10
+ # please change over there too
11
+ VERSION = "2.1.2"
12
+
13
+ ## Thrown by Parser in the event of a commandline error. Not needed if
14
+ ## you're using the Trollop::options entry.
15
+ class CommandlineError < StandardError
16
+ attr_reader :error_code
17
+
18
+ def initialize(msg, error_code = nil)
19
+ super(msg)
20
+ @error_code = error_code
21
+ end
22
+ end
23
+
24
+ ## Thrown by Parser if the user passes in '-h' or '--help'. Handled
25
+ ## automatically by Trollop#options.
26
+ class HelpNeeded < StandardError
27
+ end
28
+
29
+ ## Thrown by Parser if the user passes in '-v' or '--version'. Handled
30
+ ## automatically by Trollop#options.
31
+ class VersionNeeded < StandardError
32
+ end
33
+
34
+ ## Regex for floating point numbers
35
+ FLOAT_RE = /^-?((\d+(\.\d+)?)|(\.\d+))([eE][-+]?[\d]+)?$/
36
+
37
+ ## Regex for parameters
38
+ PARAM_RE = /^-(-|\.$|[^\d\.])/
39
+
40
+ ## The commandline parser. In typical usage, the methods in this class
41
+ ## will be handled internally by Trollop::options. In this case, only the
42
+ ## #opt, #banner and #version, #depends, and #conflicts methods will
43
+ ## typically be called.
44
+ ##
45
+ ## If you want to instantiate this class yourself (for more complicated
46
+ ## argument-parsing logic), call #parse to actually produce the output hash,
47
+ ## and consider calling it from within
48
+ ## Trollop::with_standard_exception_handling.
49
+ class Parser
50
+ ## The set of values that indicate a flag option when passed as the
51
+ ## +:type+ parameter of #opt.
52
+ FLAG_TYPES = [:flag, :bool, :boolean]
53
+
54
+ ## The set of values that indicate a single-parameter (normal) option when
55
+ ## passed as the +:type+ parameter of #opt.
56
+ ##
57
+ ## A value of +io+ corresponds to a readable IO resource, including
58
+ ## a filename, URI, or the strings 'stdin' or '-'.
59
+ SINGLE_ARG_TYPES = [:int, :integer, :string, :double, :float, :io, :date]
60
+
61
+ ## The set of values that indicate a multiple-parameter option (i.e., that
62
+ ## takes multiple space-separated values on the commandline) when passed as
63
+ ## the +:type+ parameter of #opt.
64
+ MULTI_ARG_TYPES = [:ints, :integers, :strings, :doubles, :floats, :ios, :dates]
65
+
66
+ ## The complete set of legal values for the +:type+ parameter of #opt.
67
+ TYPES = FLAG_TYPES + SINGLE_ARG_TYPES + MULTI_ARG_TYPES
68
+
69
+ INVALID_SHORT_ARG_REGEX = /[\d-]/ #:nodoc:
70
+
71
+ ## The values from the commandline that were not interpreted by #parse.
72
+ attr_reader :leftovers
73
+
74
+ ## The complete configuration hashes for each option. (Mainly useful
75
+ ## for testing.)
76
+ attr_reader :specs
77
+
78
+ ## A flag that determines whether or not to raise an error if the parser is passed one or more
79
+ ## options that were not registered ahead of time. If 'true', then the parser will simply
80
+ ## ignore options that it does not recognize.
81
+ attr_accessor :ignore_invalid_options
82
+
83
+ ## Initializes the parser, and instance-evaluates any block given.
84
+ def initialize(*a, &b)
85
+ @version = nil
86
+ @leftovers = []
87
+ @specs = {}
88
+ @long = {}
89
+ @short = {}
90
+ @order = []
91
+ @constraints = []
92
+ @stop_words = []
93
+ @stop_on_unknown = false
94
+ @educate_on_error = false
95
+
96
+ # instance_eval(&b) if b # can't take arguments
97
+ cloaker(&b).bind(self).call(*a) if b
98
+ end
99
+
100
+ ## Define an option. +name+ is the option name, a unique identifier
101
+ ## for the option that you will use internally, which should be a
102
+ ## symbol or a string. +desc+ is a string description which will be
103
+ ## displayed in help messages.
104
+ ##
105
+ ## Takes the following optional arguments:
106
+ ##
107
+ ## [+:long+] Specify the long form of the argument, i.e. the form with two dashes. If unspecified, will be automatically derived based on the argument name by turning the +name+ option into a string, and replacing any _'s by -'s.
108
+ ## [+:short+] Specify the short form of the argument, i.e. the form with one dash. If unspecified, will be automatically derived from +name+. Use :none: to not have a short value.
109
+ ## [+:type+] Require that the argument take a parameter or parameters of type +type+. For a single parameter, the value can be a member of +SINGLE_ARG_TYPES+, or a corresponding Ruby class (e.g. +Integer+ for +:int+). For multiple-argument parameters, the value can be any member of +MULTI_ARG_TYPES+ constant. If unset, the default argument type is +:flag+, meaning that the argument does not take a parameter. The specification of +:type+ is not necessary if a +:default+ is given.
110
+ ## [+:default+] Set the default value for an argument. Without a default value, the hash returned by #parse (and thus Trollop::options) will have a +nil+ value for this key unless the argument is given on the commandline. The argument type is derived automatically from the class of the default value given, so specifying a +:type+ is not necessary if a +:default+ is given. (But see below for an important caveat when +:multi+: is specified too.) If the argument is a flag, and the default is set to +true+, then if it is specified on the the commandline the value will be +false+.
111
+ ## [+:required+] If set to +true+, the argument must be provided on the commandline.
112
+ ## [+:multi+] If set to +true+, allows multiple occurrences of the option on the commandline. Otherwise, only a single instance of the option is allowed. (Note that this is different from taking multiple parameters. See below.)
113
+ ##
114
+ ## Note that there are two types of argument multiplicity: an argument
115
+ ## can take multiple values, e.g. "--arg 1 2 3". An argument can also
116
+ ## be allowed to occur multiple times, e.g. "--arg 1 --arg 2".
117
+ ##
118
+ ## Arguments that take multiple values should have a +:type+ parameter
119
+ ## drawn from +MULTI_ARG_TYPES+ (e.g. +:strings+), or a +:default:+
120
+ ## value of an array of the correct type (e.g. [String]). The
121
+ ## value of this argument will be an array of the parameters on the
122
+ ## commandline.
123
+ ##
124
+ ## Arguments that can occur multiple times should be marked with
125
+ ## +:multi+ => +true+. The value of this argument will also be an array.
126
+ ## In contrast with regular non-multi options, if not specified on
127
+ ## the commandline, the default value will be [], not nil.
128
+ ##
129
+ ## These two attributes can be combined (e.g. +:type+ => +:strings+,
130
+ ## +:multi+ => +true+), in which case the value of the argument will be
131
+ ## an array of arrays.
132
+ ##
133
+ ## There's one ambiguous case to be aware of: when +:multi+: is true and a
134
+ ## +:default+ is set to an array (of something), it's ambiguous whether this
135
+ ## is a multi-value argument as well as a multi-occurrence argument.
136
+ ## In thise case, Trollop assumes that it's not a multi-value argument.
137
+ ## If you want a multi-value, multi-occurrence argument with a default
138
+ ## value, you must specify +:type+ as well.
139
+
140
+ def opt(name, desc = "", opts = {}, &b)
141
+ raise ArgumentError, "you already have an argument named '#{name}'" if @specs.member? name
142
+
143
+ ## fill in :type
144
+ opts[:type] = # normalize
145
+ case opts[:type]
146
+ when :boolean, :bool then :flag
147
+ when :integer then :int
148
+ when :integers then :ints
149
+ when :double then :float
150
+ when :doubles then :floats
151
+ when Class
152
+ case opts[:type].name
153
+ when 'TrueClass',
154
+ 'FalseClass' then :flag
155
+ when 'String' then :string
156
+ when 'Integer' then :int
157
+ when 'Float' then :float
158
+ when 'IO' then :io
159
+ when 'Date' then :date
160
+ else
161
+ raise ArgumentError, "unsupported argument type '#{opts[:type].class.name}'"
162
+ end
163
+ when nil then nil
164
+ else
165
+ raise ArgumentError, "unsupported argument type '#{opts[:type]}'" unless TYPES.include?(opts[:type])
166
+ opts[:type]
167
+ end
168
+
169
+ ## for options with :multi => true, an array default doesn't imply
170
+ ## a multi-valued argument. for that you have to specify a :type
171
+ ## as well. (this is how we disambiguate an ambiguous situation;
172
+ ## see the docs for Parser#opt for details.)
173
+ disambiguated_default = if opts[:multi] && opts[:default].kind_of?(Array) && !opts[:type]
174
+ opts[:default].first
175
+ else
176
+ opts[:default]
177
+ end
178
+
179
+ type_from_default =
180
+ case disambiguated_default
181
+ when Integer then :int
182
+ when Numeric then :float
183
+ when TrueClass,
184
+ FalseClass then :flag
185
+ when String then :string
186
+ when IO then :io
187
+ when Date then :date
188
+ when Array
189
+ if opts[:default].empty?
190
+ if opts[:type]
191
+ raise ArgumentError, "multiple argument type must be plural" unless MULTI_ARG_TYPES.include?(opts[:type])
192
+ nil
193
+ else
194
+ raise ArgumentError, "multiple argument type cannot be deduced from an empty array for '#{opts[:default][0].class.name}'"
195
+ end
196
+ else
197
+ case opts[:default][0] # the first element determines the types
198
+ when Integer then :ints
199
+ when Numeric then :floats
200
+ when String then :strings
201
+ when IO then :ios
202
+ when Date then :dates
203
+ else
204
+ raise ArgumentError, "unsupported multiple argument type '#{opts[:default][0].class.name}'"
205
+ end
206
+ end
207
+ when nil then nil
208
+ else
209
+ raise ArgumentError, "unsupported argument type '#{opts[:default].class.name}'"
210
+ end
211
+
212
+ raise ArgumentError, ":type specification and default type don't match (default type is #{type_from_default})" if opts[:type] && type_from_default && opts[:type] != type_from_default
213
+
214
+ opts[:type] = opts[:type] || type_from_default || :flag
215
+
216
+ ## fill in :long
217
+ opts[:long] = opts[:long] ? opts[:long].to_s : name.to_s.gsub("_", "-")
218
+ opts[:long] = case opts[:long]
219
+ when /^--([^-].*)$/ then $1
220
+ when /^[^-]/ then opts[:long]
221
+ else raise ArgumentError, "invalid long option name #{opts[:long].inspect}"
222
+ end
223
+ raise ArgumentError, "long option name #{opts[:long].inspect} is already taken; please specify a (different) :long" if @long[opts[:long]]
224
+
225
+ ## fill in :short
226
+ opts[:short] = opts[:short].to_s if opts[:short] && opts[:short] != :none
227
+ opts[:short] = case opts[:short]
228
+ when /^-(.)$/ then $1
229
+ when nil, :none, /^.$/ then opts[:short]
230
+ else raise ArgumentError, "invalid short option name '#{opts[:short].inspect}'"
231
+ end
232
+
233
+ if opts[:short]
234
+ raise ArgumentError, "short option name #{opts[:short].inspect} is already taken; please specify a (different) :short" if @short[opts[:short]]
235
+ raise ArgumentError, "a short option name can't be a number or a dash" if opts[:short] =~ INVALID_SHORT_ARG_REGEX
236
+ end
237
+
238
+ ## fill in :default for flags
239
+ opts[:default] = false if opts[:type] == :flag && opts[:default].nil?
240
+
241
+ ## autobox :default for :multi (multi-occurrence) arguments
242
+ opts[:default] = [opts[:default]] if opts[:default] && opts[:multi] && !opts[:default].kind_of?(Array)
243
+
244
+ ## fill in :multi
245
+ opts[:multi] ||= false
246
+ opts[:callback] ||= b if block_given?
247
+ opts[:desc] ||= desc
248
+ @long[opts[:long]] = name
249
+ @short[opts[:short]] = name if opts[:short] && opts[:short] != :none
250
+ @specs[name] = opts
251
+ @order << [:opt, name]
252
+ end
253
+
254
+ ## Sets the version string. If set, the user can request the version
255
+ ## on the commandline. Should probably be of the form "<program name>
256
+ ## <version number>".
257
+ def version(s = nil)
258
+ s ? @version = s : @version
259
+ end
260
+
261
+ ## Sets the usage string. If set the message will be printed as the
262
+ ## first line in the help (educate) output and ending in two new
263
+ ## lines.
264
+ def usage(s = nil)
265
+ s ? @usage = s : @usage
266
+ end
267
+
268
+ ## Adds a synopsis (command summary description) right below the
269
+ ## usage line, or as the first line if usage isn't specified.
270
+ def synopsis(s = nil)
271
+ s ? @synopsis = s : @synopsis
272
+ end
273
+
274
+ ## Adds text to the help display. Can be interspersed with calls to
275
+ ## #opt to build a multi-section help page.
276
+ def banner(s)
277
+ @order << [:text, s]
278
+ end
279
+ alias_method :text, :banner
280
+
281
+ ## Marks two (or more!) options as requiring each other. Only handles
282
+ ## undirected (i.e., mutual) dependencies. Directed dependencies are
283
+ ## better modeled with Trollop::die.
284
+ def depends(*syms)
285
+ syms.each { |sym| raise ArgumentError, "unknown option '#{sym}'" unless @specs[sym] }
286
+ @constraints << [:depends, syms]
287
+ end
288
+
289
+ ## Marks two (or more!) options as conflicting.
290
+ def conflicts(*syms)
291
+ syms.each { |sym| raise ArgumentError, "unknown option '#{sym}'" unless @specs[sym] }
292
+ @constraints << [:conflicts, syms]
293
+ end
294
+
295
+ ## Defines a set of words which cause parsing to terminate when
296
+ ## encountered, such that any options to the left of the word are
297
+ ## parsed as usual, and options to the right of the word are left
298
+ ## intact.
299
+ ##
300
+ ## A typical use case would be for subcommand support, where these
301
+ ## would be set to the list of subcommands. A subsequent Trollop
302
+ ## invocation would then be used to parse subcommand options, after
303
+ ## shifting the subcommand off of ARGV.
304
+ def stop_on(*words)
305
+ @stop_words = [*words].flatten
306
+ end
307
+
308
+ ## Similar to #stop_on, but stops on any unknown word when encountered
309
+ ## (unless it is a parameter for an argument). This is useful for
310
+ ## cases where you don't know the set of subcommands ahead of time,
311
+ ## i.e., without first parsing the global options.
312
+ def stop_on_unknown
313
+ @stop_on_unknown = true
314
+ end
315
+
316
+ ## Instead of displaying "Try --help for help." on an error
317
+ ## display the usage (via educate)
318
+ def educate_on_error
319
+ @educate_on_error = true
320
+ end
321
+
322
+ ## Parses the commandline. Typically called by Trollop::options,
323
+ ## but you can call it directly if you need more control.
324
+ ##
325
+ ## throws CommandlineError, HelpNeeded, and VersionNeeded exceptions.
326
+ def parse(cmdline = ARGV)
327
+ vals = {}
328
+ required = {}
329
+
330
+ opt :version, "Print version and exit" if @version && ! (@specs[:version] || @long["version"])
331
+ opt :help, "Show this message" unless @specs[:help] || @long["help"]
332
+
333
+ @specs.each do |sym, opts|
334
+ required[sym] = true if opts[:required]
335
+ vals[sym] = opts[:default]
336
+ vals[sym] = [] if opts[:multi] && !opts[:default] # multi arguments default to [], not nil
337
+ end
338
+
339
+ resolve_default_short_options!
340
+
341
+ ## resolve symbols
342
+ given_args = {}
343
+ @leftovers = each_arg cmdline do |arg, params|
344
+ ## handle --no- forms
345
+ arg, negative_given = if arg =~ /^--no-([^-]\S*)$/
346
+ ["--#{$1}", true]
347
+ else
348
+ [arg, false]
349
+ end
350
+
351
+ sym = case arg
352
+ when /^-([^-])$/ then @short[$1]
353
+ when /^--([^-]\S*)$/ then @long[$1] || @long["no-#{$1}"]
354
+ else raise CommandlineError, "invalid argument syntax: '#{arg}'"
355
+ end
356
+
357
+ sym = nil if arg =~ /--no-/ # explicitly invalidate --no-no- arguments
358
+
359
+ next 0 if ignore_invalid_options && !sym
360
+ raise CommandlineError, "unknown argument '#{arg}'" unless sym
361
+
362
+ if given_args.include?(sym) && !@specs[sym][:multi]
363
+ raise CommandlineError, "option '#{arg}' specified multiple times"
364
+ end
365
+
366
+ given_args[sym] ||= {}
367
+ given_args[sym][:arg] = arg
368
+ given_args[sym][:negative_given] = negative_given
369
+ given_args[sym][:params] ||= []
370
+
371
+ # The block returns the number of parameters taken.
372
+ num_params_taken = 0
373
+
374
+ unless params.nil?
375
+ if SINGLE_ARG_TYPES.include?(@specs[sym][:type])
376
+ given_args[sym][:params] << params[0, 1] # take the first parameter
377
+ num_params_taken = 1
378
+ elsif MULTI_ARG_TYPES.include?(@specs[sym][:type])
379
+ given_args[sym][:params] << params # take all the parameters
380
+ num_params_taken = params.size
381
+ end
382
+ end
383
+
384
+ num_params_taken
385
+ end
386
+
387
+ ## check for version and help args
388
+ raise VersionNeeded if given_args.include? :version
389
+ raise HelpNeeded if given_args.include? :help
390
+
391
+ ## check constraint satisfaction
392
+ @constraints.each do |type, syms|
393
+ constraint_sym = syms.find { |sym| given_args[sym] }
394
+ next unless constraint_sym
395
+
396
+ case type
397
+ when :depends
398
+ syms.each { |sym| raise CommandlineError, "--#{@specs[constraint_sym][:long]} requires --#{@specs[sym][:long]}" unless given_args.include? sym }
399
+ when :conflicts
400
+ syms.each { |sym| raise CommandlineError, "--#{@specs[constraint_sym][:long]} conflicts with --#{@specs[sym][:long]}" if given_args.include?(sym) && (sym != constraint_sym) }
401
+ end
402
+ end
403
+
404
+ required.each do |sym, val|
405
+ raise CommandlineError, "option --#{@specs[sym][:long]} must be specified" unless given_args.include? sym
406
+ end
407
+
408
+ ## parse parameters
409
+ given_args.each do |sym, given_data|
410
+ arg, params, negative_given = given_data.values_at :arg, :params, :negative_given
411
+
412
+ opts = @specs[sym]
413
+ if params.empty? && opts[:type] != :flag
414
+ raise CommandlineError, "option '#{arg}' needs a parameter" unless opts[:default]
415
+ params << (opts[:default].kind_of?(Array) ? opts[:default].clone : [opts[:default]])
416
+ end
417
+
418
+ vals["#{sym}_given".intern] = true # mark argument as specified on the commandline
419
+
420
+ case opts[:type]
421
+ when :flag
422
+ vals[sym] = (sym.to_s =~ /^no_/ ? negative_given : !negative_given)
423
+ when :int, :ints
424
+ vals[sym] = params.map { |pg| pg.map { |p| parse_integer_parameter p, arg } }
425
+ when :float, :floats
426
+ vals[sym] = params.map { |pg| pg.map { |p| parse_float_parameter p, arg } }
427
+ when :string, :strings
428
+ vals[sym] = params.map { |pg| pg.map(&:to_s) }
429
+ when :io, :ios
430
+ vals[sym] = params.map { |pg| pg.map { |p| parse_io_parameter p, arg } }
431
+ when :date, :dates
432
+ vals[sym] = params.map { |pg| pg.map { |p| parse_date_parameter p, arg } }
433
+ end
434
+
435
+ if SINGLE_ARG_TYPES.include?(opts[:type])
436
+ if opts[:multi] # multiple options, each with a single parameter
437
+ vals[sym] = vals[sym].map { |p| p[0] }
438
+ else # single parameter
439
+ vals[sym] = vals[sym][0][0]
440
+ end
441
+ elsif MULTI_ARG_TYPES.include?(opts[:type]) && !opts[:multi]
442
+ vals[sym] = vals[sym][0] # single option, with multiple parameters
443
+ end
444
+ # else: multiple options, with multiple parameters
445
+
446
+ opts[:callback].call(vals[sym]) if opts.key?(:callback)
447
+ end
448
+
449
+ ## modify input in place with only those
450
+ ## arguments we didn't process
451
+ cmdline.clear
452
+ @leftovers.each { |l| cmdline << l }
453
+
454
+ ## allow openstruct-style accessors
455
+ class << vals
456
+ def method_missing(m, *_args)
457
+ self[m] || self[m.to_s]
458
+ end
459
+ end
460
+ vals
461
+ end
462
+
463
+ def parse_date_parameter(param, arg) #:nodoc:
464
+ begin
465
+ require 'chronic'
466
+ time = Chronic.parse(param)
467
+ rescue LoadError
468
+ # chronic is not available
469
+ end
470
+ time ? Date.new(time.year, time.month, time.day) : Date.parse(param)
471
+ rescue ArgumentError
472
+ raise CommandlineError, "option '#{arg}' needs a date"
473
+ end
474
+
475
+ ## Print the help message to +stream+.
476
+ def educate(stream = $stdout)
477
+ width # hack: calculate it now; otherwise we have to be careful not to
478
+ # call this unless the cursor's at the beginning of a line.
479
+ left = {}
480
+ @specs.each do |name, spec|
481
+ left[name] =
482
+ (spec[:short] && spec[:short] != :none ? "-#{spec[:short]}" : "") +
483
+ (spec[:short] && spec[:short] != :none ? ", " : "") + "--#{spec[:long]}" +
484
+ case spec[:type]
485
+ when :flag then ""
486
+ when :int then "=<i>"
487
+ when :ints then "=<i+>"
488
+ when :string then "=<s>"
489
+ when :strings then "=<s+>"
490
+ when :float then "=<f>"
491
+ when :floats then "=<f+>"
492
+ when :io then "=<filename/uri>"
493
+ when :ios then "=<filename/uri+>"
494
+ when :date then "=<date>"
495
+ when :dates then "=<date+>"
496
+ end +
497
+ (spec[:type] == :flag && spec[:default] ? ", --no-#{spec[:long]}" : "")
498
+ end
499
+
500
+ leftcol_width = left.values.map(&:length).max || 0
501
+ rightcol_start = leftcol_width + 6 # spaces
502
+
503
+ unless @order.size > 0 && @order.first.first == :text
504
+ command_name = File.basename($0).gsub(/\.[^.]+$/, '')
505
+ stream.puts "Usage: #{command_name} #{@usage}\n" if @usage
506
+ stream.puts "#{@synopsis}\n" if @synopsis
507
+ stream.puts if @usage || @synopsis
508
+ stream.puts "#{@version}\n" if @version
509
+ stream.puts "Options:"
510
+ end
511
+
512
+ @order.each do |what, opt|
513
+ if what == :text
514
+ stream.puts wrap(opt)
515
+ next
516
+ end
517
+
518
+ spec = @specs[opt]
519
+ stream.printf " %-#{leftcol_width}s ", left[opt]
520
+ desc = spec[:desc] + begin
521
+ default_s = case spec[:default]
522
+ when $stdout then "<stdout>"
523
+ when $stdin then "<stdin>"
524
+ when $stderr then "<stderr>"
525
+ when Array
526
+ spec[:default].join(", ")
527
+ else
528
+ spec[:default].to_s
529
+ end
530
+
531
+ if spec[:default]
532
+ if spec[:desc] =~ /\.$/
533
+ " (Default: #{default_s})"
534
+ else
535
+ " (default: #{default_s})"
536
+ end
537
+ else
538
+ ""
539
+ end
540
+ end
541
+ stream.puts wrap(desc, :width => width - rightcol_start - 1, :prefix => rightcol_start)
542
+ end
543
+ end
544
+
545
+ def width #:nodoc:
546
+ @width ||= if $stdout.tty?
547
+ begin
548
+ require 'io/console'
549
+ IO.console.winsize.last
550
+ rescue LoadError, NoMethodError, Errno::ENOTTY, Errno::EBADF, Errno::EINVAL
551
+ legacy_width
552
+ end
553
+ else
554
+ 80
555
+ end
556
+ end
557
+
558
+ def legacy_width
559
+ # Support for older Rubies where io/console is not available
560
+ `tput cols`.to_i
561
+ rescue Errno::ENOENT
562
+ 80
563
+ end
564
+ private :legacy_width
565
+
566
+ def wrap(str, opts = {}) # :nodoc:
567
+ if str == ""
568
+ [""]
569
+ else
570
+ inner = false
571
+ str.split("\n").map do |s|
572
+ line = wrap_line s, opts.merge(:inner => inner)
573
+ inner = true
574
+ line
575
+ end.flatten
576
+ end
577
+ end
578
+
579
+ ## The per-parser version of Trollop::die (see that for documentation).
580
+ def die(arg, msg = nil, error_code = nil)
581
+ if msg
582
+ $stderr.puts "Error: argument --#{@specs[arg][:long]} #{msg}."
583
+ else
584
+ $stderr.puts "Error: #{arg}."
585
+ end
586
+ if @educate_on_error
587
+ $stderr.puts
588
+ educate $stderr
589
+ else
590
+ $stderr.puts "Try --help for help."
591
+ end
592
+ exit(error_code || -1)
593
+ end
594
+
595
+ private
596
+
597
+ ## yield successive arg, parameter pairs
598
+ def each_arg(args)
599
+ remains = []
600
+ i = 0
601
+
602
+ until i >= args.length
603
+ return remains += args[i..-1] if @stop_words.member? args[i]
604
+ case args[i]
605
+ when /^--$/ # arg terminator
606
+ return remains += args[(i + 1)..-1]
607
+ when /^--(\S+?)=(.*)$/ # long argument with equals
608
+ yield "--#{$1}", [$2]
609
+ i += 1
610
+ when /^--(\S+)$/ # long argument
611
+ params = collect_argument_parameters(args, i + 1)
612
+ if params.empty?
613
+ yield args[i], nil
614
+ i += 1
615
+ else
616
+ num_params_taken = yield args[i], params
617
+ unless num_params_taken
618
+ if @stop_on_unknown
619
+ return remains += args[i + 1..-1]
620
+ else
621
+ remains += params
622
+ end
623
+ end
624
+ i += 1 + num_params_taken
625
+ end
626
+ when /^-(\S+)$/ # one or more short arguments
627
+ shortargs = $1.split(//)
628
+ shortargs.each_with_index do |a, j|
629
+ if j == (shortargs.length - 1)
630
+ params = collect_argument_parameters(args, i + 1)
631
+ if params.empty?
632
+ yield "-#{a}", nil
633
+ i += 1
634
+ else
635
+ num_params_taken = yield "-#{a}", params
636
+ unless num_params_taken
637
+ if @stop_on_unknown
638
+ return remains += args[i + 1..-1]
639
+ else
640
+ remains += params
641
+ end
642
+ end
643
+ i += 1 + num_params_taken
644
+ end
645
+ else
646
+ yield "-#{a}", nil
647
+ end
648
+ end
649
+ else
650
+ if @stop_on_unknown
651
+ return remains += args[i..-1]
652
+ else
653
+ remains << args[i]
654
+ i += 1
655
+ end
656
+ end
657
+ end
658
+
659
+ remains
660
+ end
661
+
662
+ def parse_integer_parameter(param, arg)
663
+ raise CommandlineError, "option '#{arg}' needs an integer" unless param =~ /^-?[\d_]+$/
664
+ param.to_i
665
+ end
666
+
667
+ def parse_float_parameter(param, arg)
668
+ raise CommandlineError, "option '#{arg}' needs a floating-point number" unless param =~ FLOAT_RE
669
+ param.to_f
670
+ end
671
+
672
+ def parse_io_parameter(param, arg)
673
+ if param =~ /^(stdin|-)$/i
674
+ $stdin
675
+ else
676
+ require 'open-uri'
677
+ begin
678
+ open param
679
+ rescue SystemCallError => e
680
+ raise CommandlineError, "file or url for option '#{arg}' cannot be opened: #{e.message}"
681
+ end
682
+ end
683
+ end
684
+
685
+ def collect_argument_parameters(args, start_at)
686
+ params = []
687
+ pos = start_at
688
+ while args[pos] && args[pos] !~ PARAM_RE && !@stop_words.member?(args[pos]) do
689
+ params << args[pos]
690
+ pos += 1
691
+ end
692
+ params
693
+ end
694
+
695
+ def resolve_default_short_options!
696
+ @order.each do |type, name|
697
+ opts = @specs[name]
698
+ next if type != :opt || opts[:short]
699
+
700
+ c = opts[:long].split(//).find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) }
701
+ if c # found a character to use
702
+ opts[:short] = c
703
+ @short[c] = name
704
+ end
705
+ end
706
+ end
707
+
708
+ def wrap_line(str, opts = {})
709
+ prefix = opts[:prefix] || 0
710
+ width = opts[:width] || (self.width - 1)
711
+ start = 0
712
+ ret = []
713
+ until start > str.length
714
+ nextt =
715
+ if start + width >= str.length
716
+ str.length
717
+ else
718
+ x = str.rindex(/\s/, start + width)
719
+ x = str.index(/\s/, start) if x && x < start
720
+ x || str.length
721
+ end
722
+ ret << ((ret.empty? && !opts[:inner]) ? "" : " " * prefix) + str[start...nextt]
723
+ start = nextt + 1
724
+ end
725
+ ret
726
+ end
727
+
728
+ ## instance_eval but with ability to handle block arguments
729
+ ## thanks to _why: http://redhanded.hobix.com/inspect/aBlockCostume.html
730
+ def cloaker(&b)
731
+ (class << self; self; end).class_eval do
732
+ define_method :cloaker_, &b
733
+ meth = instance_method :cloaker_
734
+ remove_method :cloaker_
735
+ meth
736
+ end
737
+ end
738
+ end
739
+
740
+ ## The easy, syntactic-sugary entry method into Trollop. Creates a Parser,
741
+ ## passes the block to it, then parses +args+ with it, handling any errors or
742
+ ## requests for help or version information appropriately (and then exiting).
743
+ ## Modifies +args+ in place. Returns a hash of option values.
744
+ ##
745
+ ## The block passed in should contain zero or more calls to +opt+
746
+ ## (Parser#opt), zero or more calls to +text+ (Parser#text), and
747
+ ## probably a call to +version+ (Parser#version).
748
+ ##
749
+ ## The returned block contains a value for every option specified with
750
+ ## +opt+. The value will be the value given on the commandline, or the
751
+ ## default value if the option was not specified on the commandline. For
752
+ ## every option specified on the commandline, a key "<option
753
+ ## name>_given" will also be set in the hash.
754
+ ##
755
+ ## Example:
756
+ ##
757
+ ## require 'trollop'
758
+ ## opts = Trollop::options do
759
+ ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
760
+ ## opt :name, "Monkey name", :type => :string # a string --name <s>, defaulting to nil
761
+ ## opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
762
+ ## end
763
+ ##
764
+ ## ## if called with no arguments
765
+ ## p opts # => {:monkey=>false, :name=>nil, :num_limbs=>4, :help=>false}
766
+ ##
767
+ ## ## if called with --monkey
768
+ ## p opts # => {:monkey=>true, :name=>nil, :num_limbs=>4, :help=>false, :monkey_given=>true}
769
+ ##
770
+ ## See more examples at http://trollop.rubyforge.org.
771
+ def options(args = ARGV, *a, &b)
772
+ @last_parser = Parser.new(*a, &b)
773
+ with_standard_exception_handling(@last_parser) { @last_parser.parse args }
774
+ end
775
+
776
+ ## If Trollop::options doesn't do quite what you want, you can create a Parser
777
+ ## object and call Parser#parse on it. That method will throw CommandlineError,
778
+ ## HelpNeeded and VersionNeeded exceptions when necessary; if you want to
779
+ ## have these handled for you in the standard manner (e.g. show the help
780
+ ## and then exit upon an HelpNeeded exception), call your code from within
781
+ ## a block passed to this method.
782
+ ##
783
+ ## Note that this method will call System#exit after handling an exception!
784
+ ##
785
+ ## Usage example:
786
+ ##
787
+ ## require 'trollop'
788
+ ## p = Trollop::Parser.new do
789
+ ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
790
+ ## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
791
+ ## end
792
+ ##
793
+ ## opts = Trollop::with_standard_exception_handling p do
794
+ ## o = p.parse ARGV
795
+ ## raise Trollop::HelpNeeded if ARGV.empty? # show help screen
796
+ ## o
797
+ ## end
798
+ ##
799
+ ## Requires passing in the parser object.
800
+
801
+ def with_standard_exception_handling(parser)
802
+ yield
803
+ rescue CommandlineError => e
804
+ parser.die(e.message, nil, e.error_code)
805
+ rescue HelpNeeded
806
+ parser.educate
807
+ exit
808
+ rescue VersionNeeded
809
+ puts parser.version
810
+ exit
811
+ end
812
+
813
+ ## Informs the user that their usage of 'arg' was wrong, as detailed by
814
+ ## 'msg', and dies. Example:
815
+ ##
816
+ ## options do
817
+ ## opt :volume, :default => 0.0
818
+ ## end
819
+ ##
820
+ ## die :volume, "too loud" if opts[:volume] > 10.0
821
+ ## die :volume, "too soft" if opts[:volume] < 0.1
822
+ ##
823
+ ## In the one-argument case, simply print that message, a notice
824
+ ## about -h, and die. Example:
825
+ ##
826
+ ## options do
827
+ ## opt :whatever # ...
828
+ ## end
829
+ ##
830
+ ## Trollop::die "need at least one filename" if ARGV.empty?
831
+ def die(arg, msg = nil, error_code = nil)
832
+ if @last_parser
833
+ @last_parser.die arg, msg, error_code
834
+ else
835
+ raise ArgumentError, "Trollop::die can only be called after Trollop::options"
836
+ end
837
+ end
838
+
839
+ ## Displays the help message and dies. Example:
840
+ ##
841
+ ## options do
842
+ ## opt :volume, :default => 0.0
843
+ ## banner <<-EOS
844
+ ## Usage:
845
+ ## #$0 [options] <name>
846
+ ## where [options] are:
847
+ ## EOS
848
+ ## end
849
+ ##
850
+ ## Trollop::educate if ARGV.empty?
851
+ def educate
852
+ if @last_parser
853
+ @last_parser.educate
854
+ exit
855
+ else
856
+ raise ArgumentError, "Trollop::educate can only be called after Trollop::options"
857
+ end
858
+ end
859
+
860
+ module_function :options, :die, :educate, :with_standard_exception_handling
861
+ end # module
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PuppetRepl
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/puppet-repl.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "puppet-repl"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Osman"]
12
- s.date = "2016-04-13"
12
+ s.date = "2016-04-17"
13
13
  s.description = "A interactive command line tool for evaluating the puppet language"
14
14
  s.email = "corey@nwops.io"
15
15
  s.executables = ["prepl"]
@@ -41,9 +41,12 @@ Gem::Specification.new do |s|
41
41
  "lib/puppet-repl/support/node.rb",
42
42
  "lib/puppet-repl/support/play.rb",
43
43
  "lib/puppet-repl/support/scope.rb",
44
+ "lib/trollop.rb",
44
45
  "lib/version.rb",
45
46
  "puppet-repl.gemspec",
46
47
  "spec/fixtures/environments/production/manifests/site.pp",
48
+ "spec/fixtures/sample_manifest.pp",
49
+ "spec/prepl_spec.rb",
47
50
  "spec/puppet-repl_spec.rb",
48
51
  "spec/spec_helper.rb",
49
52
  "spec/support_spec.rb"
@@ -0,0 +1,2 @@
1
+ $var1 = 'test'
2
+ file{"/tmp/${var1}.txt": ensure => present, mode => '0755'}
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'prepl' do
4
+ let(:fixtures_file) do
5
+ File.join(fixtures_dir, 'sample_manifest.pp')
6
+ end
7
+
8
+ let(:file_url) do
9
+ 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'
10
+ end
11
+
12
+ it do
13
+ expect(`echo 'file{"/tmp/test":}'| bundle exec bin/prepl`)
14
+ .to match(/Puppet::Type::File/)
15
+ end
16
+
17
+ it do
18
+ expect(`bundle exec bin/prepl #{fixtures_file} --run-once`)
19
+ .to match(/Puppet::Type::File/)
20
+ end
21
+ it do
22
+ expect(`bundle exec bin/prepl --play #{fixtures_file} --run-once`)
23
+ .to match(/Puppet::Type::File/)
24
+ end
25
+ it do
26
+ expect(`bundle exec bin/prepl --play #{file_url} --run-once`)
27
+ .to match(/Puppet::Type::File/)
28
+ end
29
+ end
@@ -33,7 +33,11 @@ describe "PuppetRepl" do
33
33
  'help'
34
34
  end
35
35
  it 'can show the help screen' do
36
- repl_output = /Ruby Version: #{RUBY_VERSION}\nPuppet Version: \d.\d.\d\nPuppet Repl Version: \d.\d.\d\nCreated by: NWOps <corey@nwops.io>\nType \"exit\", \"functions\", \"vars\", \"krt\", \"facts\", \"resources\", \"classes\",\n \"reset\", or \"help\" for more information.\n\n/
36
+ repl_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"facts\", \"resources\", \"classes\",\n \"play\",\"reset\", or \"help\" for more information.\n\n/
37
+ expect{repl.handle_input(input)}.to output(/Ruby Version: #{RUBY_VERSION}\n/).to_stdout
38
+ expect{repl.handle_input(input)}.to output(/Puppet Version: \d.\d.\d\n/).to_stdout
39
+ expect{repl.handle_input(input)}.to output(/Puppet Repl Version: \d.\d.\d\n/).to_stdout
40
+ expect{repl.handle_input(input)}.to output(/Created by: NWOps <corey@nwops.io>\n/).to_stdout
37
41
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
38
42
  end
39
43
  end
@@ -43,7 +47,7 @@ describe "PuppetRepl" do
43
47
  ""
44
48
  end
45
49
  it 'can run' do
46
- repl_output = ''
50
+ repl_output = " => \n"
47
51
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
48
52
  end
49
53
  describe 'space' do
@@ -51,7 +55,7 @@ describe "PuppetRepl" do
51
55
  " "
52
56
  end
53
57
  it 'can run' do
54
- repl_output = ''
58
+ repl_output = " => \n"
55
59
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
56
60
  end
57
61
  end
@@ -67,6 +71,23 @@ describe "PuppetRepl" do
67
71
  end
68
72
  end
69
73
 
74
+ describe 'play' do
75
+ let(:fixtures_file) do
76
+ File.join(fixtures_dir, 'sample_manifest.pp')
77
+ end
78
+
79
+ let(:file_url) do
80
+ 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'
81
+ end
82
+ it 'file' do
83
+ expect{repl.handle_input("play #{fixtures_file}")}.to output(/Puppet::Type::File/).to_stdout
84
+ end
85
+ it 'url' do
86
+ expect{repl.handle_input("play #{file_url}")}.to output(/Puppet::Type::File/).to_stdout
87
+ end
88
+
89
+ end
90
+
70
91
  describe 'variables' do
71
92
  let(:input) do
72
93
  "$file_path = '/tmp/test2.txt'"
@@ -108,17 +129,15 @@ describe "PuppetRepl" do
108
129
  end
109
130
 
110
131
  describe 'reset' do
111
- before(:each) do
112
- repl.handle_input(input)
113
- end
114
132
  let(:input) do
115
133
  "file{'/tmp/reset': ensure => present}"
116
134
  end
117
135
 
118
- it 'can process a each block' do
119
- repl.handle_input('reset')
136
+ it 'can process a file' do
120
137
  repl_output = /Puppet::Type::File/
121
138
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
139
+ repl.handle_input('reset')
140
+ expect{repl.handle_input(input)}.to output(repl_output).to_stdout
122
141
  end
123
142
 
124
143
  describe 'loglevel' do
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.1.0
4
+ version: 0.1.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: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -112,9 +112,12 @@ files:
112
112
  - lib/puppet-repl/support/node.rb
113
113
  - lib/puppet-repl/support/play.rb
114
114
  - lib/puppet-repl/support/scope.rb
115
+ - lib/trollop.rb
115
116
  - lib/version.rb
116
117
  - puppet-repl.gemspec
117
118
  - spec/fixtures/environments/production/manifests/site.pp
119
+ - spec/fixtures/sample_manifest.pp
120
+ - spec/prepl_spec.rb
118
121
  - spec/puppet-repl_spec.rb
119
122
  - spec/spec_helper.rb
120
123
  - spec/support_spec.rb