puppet-repl 0.0.8 → 0.1.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: b8b2d91eeef5f922cd54569176f6085199647745
4
- data.tar.gz: 54320984760c3e54982a9bafda14b5c7742049c5
3
+ metadata.gz: 82f04618f457e0c269f510e98978755cad93858a
4
+ data.tar.gz: 354e81a9f221f4ae4752255b2dac80f9d49ea4d7
5
5
  SHA512:
6
- metadata.gz: 6f289d12177afa7d7888699f6b1e8afa65b0ada85bc1969019365af520289404969e64f8654e7ed019a7161c8d1b7278b2ef9f863740862f548e226cd2a9e267
7
- data.tar.gz: 1e7434a150bb7543d64f19d26c538d67527e47856a505e43dd3795812627732e6f2a9da9b30cf6948a4f1ac7500ebf12228bca6c5cab2aa2e7fb2b104cc65f8f
6
+ metadata.gz: 0b92c9c4be02ec0a64ae0b2a06f5fea0d69ef10207ee671597fddc76a6e0c94804571afbb477953330288a588aac3b91e29757baf7b46c592f8fbfc1f635f4a7
7
+ data.tar.gz: 82c321a30737266061664ad3e0d2d4b3a5c9ba66a7c6e882c7dfe61df2fac4ba3f9b9eb07b12c74827f1cdeda54ba6042f476d26a19e7e3e975e172cbee0e5b4
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gem 'awesome_print'
5
5
 
6
6
  group :test do
7
7
  gem "rspec"
8
+ gem 'rspec-puppet'
8
9
  gem "bundler"
9
10
  gem "jeweler", "~> 2.0.1"
10
11
  gem "simplecov", ">= 0"
data/Gemfile.lock CHANGED
@@ -81,6 +81,8 @@ 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
84
86
  rspec-support (3.4.1)
85
87
  simplecov (0.11.2)
86
88
  docile (~> 1.1.0)
@@ -103,6 +105,7 @@ DEPENDENCIES
103
105
  rake
104
106
  rdoc (~> 3.12)
105
107
  rspec
108
+ rspec-puppet
106
109
  simplecov
107
110
 
108
111
  BUNDLED WITH
data/README.md CHANGED
@@ -26,6 +26,10 @@ A interactive command line tool for evaluating the puppet language.
26
26
  ## Compatibility
27
27
  Requires Puppet 3.8+ and only uses the future parser.
28
28
 
29
+ ## Production usage
30
+ The puppet repl is a developer tool that should only be used when writing puppet code. Although it might seem useful
31
+ to install on your production puppet master. Please do not install because of the puppet-repl gem dependencies that might conflict with your existing environment.
32
+
29
33
  ## Installation
30
34
  `gem install puppet-repl`
31
35
 
@@ -33,7 +37,14 @@ Requires Puppet 3.8+ and only uses the future parser.
33
37
  puppet-repl will load all functions from your basemodulepath and environmentpath.
34
38
 
35
39
  This means if you run `puppet module install puppetlabs-stdlib` and they will be available
36
- in the repl.
40
+ in the repl.
41
+
42
+ ## Interactive demo
43
+ I have put together a repo with a few setup instructions that will assist you in setting up a "mock" environment
44
+ 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.
46
+
47
+ https://github.com/nwops/puppet-repl-demo
37
48
 
38
49
  ## Usage
39
50
  Puppet-repl will only parse and evaulate your code. It will not build a catalog
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.1.0
@@ -10,15 +10,22 @@ module AwesomePrint
10
10
  def cast_with_puppet_resource(object, type)
11
11
  cast = cast_without_puppet_resource(object, type)
12
12
  if (defined?(::Puppet::Type)) && (object.is_a?(::Puppet::Type))
13
- cast = :puppet_resource_instance
13
+ 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))
17
+ cast = :puppet_resource
14
18
  end
15
19
  cast
16
20
  end
17
21
 
18
- def awesome_puppet_resource_instance(object)
19
- '' if object.nil?
20
- title = object.title
21
- name = object.name
22
+ def awesome_puppet_resource(object)
23
+ return '' if object.nil?
24
+ awesome_puppet_type(object.to_ral)
25
+ end
26
+
27
+ def awesome_puppet_type(object)
28
+ return '' if object.nil?
22
29
  h = object.to_hash.merge(:name => object.name, :title => object.title)
23
30
  res_str = awesome_hash(h)
24
31
  "#{object.class} #{res_str.gsub(':', '')}"
@@ -49,6 +49,8 @@ module PuppetRepl
49
49
  return output.first
50
50
  end
51
51
  return output
52
+ elsif result.instance_of?(Puppet::Pops::Types::PResourceType)
53
+ return to_resource_declaration(result)
52
54
  end
53
55
  result
54
56
  end
@@ -72,58 +74,43 @@ module PuppetRepl
72
74
  end
73
75
 
74
76
  def handle_input(input)
75
- case input
76
- when 'help'
77
- PuppetRepl::Cli.print_repl_desc
78
- when 'functions'
79
- puts function_map.keys.sort
80
- when /^:set/
81
- handle_set(input)
82
- when 'facts'
83
- vars = Hash[ node.facts.map { |k, v| [k.to_s, v] } ]
84
- ap(vars, {:sort_keys => true, :indent => -1})
85
- when '_'
86
- puts(" => #{@last_item}")
87
- when 'vars'
88
- vars = scope.to_hash.delete_if {| key, value | node.facts.key?(key.to_sym) }
89
- vars['facts'] = 'removed by the puppet-repl'
90
- ap 'Facts were removed for easier viewing'
91
- ap(vars, {:sort_keys => true, :indent => -1})
92
- when 'environment'
93
- puts "Puppet Environment: #{puppet_env_name}"
94
- when 'vars'
95
- ap(scope.to_hash, {:sort_keys => true, :indent => 0})
96
- when 'exit'
97
- exit 0
98
- when 'reset'
99
- @scope = nil
100
- # initilize scope again
101
- scope
102
- set_log_level(log_level)
103
- when 'krt'
104
- ap(known_resource_types, {:sort_keys => true, :indent => -1})
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)
105
83
  else
106
- begin
107
- result = puppet_eval(input)
108
- @last_item = result
109
- print " => "
110
- output = normalize_output(result)
111
- if output.nil?
112
- puts ""
113
- else
114
- ap(output)
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
115
113
  end
116
- rescue ArgumentError => e
117
- print " => "
118
- puts e.message.fatal
119
- rescue Puppet::ResourceError => e
120
- print " => "
121
- puts e.message.fatal
122
- rescue Puppet::ParseErrorWithIssue => e
123
- print " => "
124
- puts e.message.fatal
125
- rescue Exception => e
126
- puts e.message.fatal
127
114
  end
128
115
  end
129
116
  end
@@ -134,17 +121,32 @@ Ruby Version: #{RUBY_VERSION}
134
121
  Puppet Version: #{Puppet.version}
135
122
  Puppet Repl Version: #{PuppetRepl::VERSION}
136
123
  Created by: NWOps <corey@nwops.io>
137
- Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more information.
124
+ Type "exit", "functions", "vars", "krt", "facts", "resources", "classes",
125
+ "reset", or "help" for more information.
138
126
 
139
127
  EOT
140
128
  end
141
129
 
142
- def self.start
130
+ def read_loop
131
+ while buf = Readline.readline(">> ", true)
132
+ handle_input(buf)
133
+ end
134
+ end
135
+
136
+ # start reads from stdin or from a file
137
+ # if from stdin, the repl will process the input and exit
138
+ # if from a file, the repl will process the file and continue to prompt
139
+ # @param [Scope] puppet scope object
140
+ def self.start(options={:scope => nil})
143
141
  print_repl_desc
144
142
  repl_obj = new
145
- while buf = Readline.readline(">> ", true)
146
- repl_obj.handle_input(buf)
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
147
  end
148
+ repl_obj.initialize_from_scope(options[:scope])
149
+ repl_obj.read_loop
148
150
  end
149
151
  end
150
152
  end
@@ -6,6 +6,15 @@ module PuppetRepl
6
6
  def create_compiler(node)
7
7
  Puppet::Parser::Compiler.new(node)
8
8
  end
9
+
10
+ def compiler
11
+ @compiler
12
+ end
13
+
14
+ def set_compiler(value)
15
+ @compiler = value
16
+ end
17
+
9
18
  end
10
19
  end
11
20
  end
@@ -7,17 +7,25 @@ module PuppetRepl
7
7
  unless @puppet_environment
8
8
  do_initialize
9
9
  @puppet_environment = Puppet::Node::Environment.create(
10
- puppet_env_name,
11
- module_dirs,
12
- manifests_dir
10
+ default_puppet_env_name,
11
+ default_modules_paths,
12
+ default_manifests_dir
13
13
  )
14
14
  end
15
15
  @puppet_environment
16
16
  end
17
17
 
18
- # the cached name of the environment
18
+ def set_environment(value)
19
+ @puppet_environment = value
20
+ end
21
+
19
22
  def puppet_env_name
20
- @penv ||= ENV['PUPPET_ENV'] || Puppet[:environment]
23
+ puppet_environment.name
24
+ end
25
+
26
+ # the cached name of the environment
27
+ def default_puppet_env_name
28
+ ENV['PUPPET_ENV'] || Puppet[:environment]
21
29
  end
22
30
 
23
31
  # currently this is not being used
@@ -7,10 +7,18 @@ module PuppetRepl
7
7
  'operatingsystem=RedHat and operatingsystemrelease=/^7/ and architecture=x86_64 and facterversion=/^2.4\./'
8
8
  end
9
9
 
10
+ def set_facts(value)
11
+ @facts = value
12
+ end
13
+
10
14
  # uses facterdb (cached facts) and retrives the facts given a filter
11
- def facts
15
+ # creates a new facts object
16
+ # we could also use fact_merge to get real facts from the real system or puppetdb
17
+ def default_facts
12
18
  unless @facts
13
- @facts ||= FacterDB.get_facts(facterdb_filter).first
19
+ node_facts = FacterDB.get_facts(facterdb_filter).first
20
+ values = Hash[ node_facts.map { |k, v| [k.to_s, v] } ]
21
+ @facts ||= Puppet::Node::Facts.new(values['fqdn'], values)
14
22
  end
15
23
  @facts
16
24
  end
@@ -1,7 +1,9 @@
1
1
  module PuppetRepl
2
2
  module Support
3
3
  module Functions
4
- # returns a array of function files
4
+ # returns a array of function files which is only required
5
+ # when displaying the function map, puppet will load each function on demand
6
+ # in the future we may want to utilize the puppet loaders to find these things
5
7
  def function_files
6
8
  search_dirs = lib_dirs.map do |lib_dir|
7
9
  [File.join(lib_dir, 'puppet', 'functions', '**', '*.rb'),
@@ -16,6 +18,11 @@ module PuppetRepl
16
18
  Dir.glob(search_dirs.flatten)
17
19
  end
18
20
 
21
+ # returns either the module name or puppet version
22
+ def mod_finder
23
+ @mod_finder ||= Regexp.new('\/([\w\-\.]+)\/lib')
24
+ end
25
+
19
26
  # returns a map of functions
20
27
  def function_map
21
28
  unless @functions
@@ -31,7 +38,31 @@ module PuppetRepl
31
38
  end
32
39
  @functions
33
40
  end
34
-
41
+
42
+ # returns an array of module loaders that we may need to use in the future
43
+ # in order to parse all types of code (ie. functions) For now this is not
44
+ # being used.
45
+ def resolve_paths(loaders)
46
+ mod_resolver = loaders.instance_variable_get(:@module_resolver)
47
+ all_mods = mod_resolver.instance_variable_get(:@all_module_loaders)
48
+ end
49
+
50
+ # gather all the lib dirs
51
+ def lib_dirs
52
+ dirs = modules_paths.map do |mod_dir|
53
+ Dir["#{mod_dir}/*/lib"].entries
54
+ end.flatten
55
+ dirs + [puppet_repl_lib_dir]
56
+ end
57
+
58
+ # load all the lib dirs so puppet can find the functions
59
+ # at this time, this function is not being used
60
+ def load_lib_dirs
61
+ lib_dirs.each do |lib|
62
+ $LOAD_PATH << lib
63
+ end
64
+ end
65
+
35
66
  # def functions
36
67
  # @functions = []
37
68
  # @functions << compiler.loaders.static_loader.loaded.keys.find_all {|l| l.type == :function}
@@ -0,0 +1,65 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module InputResponders
4
+ def help(args=[])
5
+ PuppetRepl::Cli.print_repl_desc
6
+ end
7
+
8
+ def facts(args=[])
9
+ # convert symbols to keys
10
+ vars = node.facts.values
11
+ ap(vars, {:sort_keys => true, :indent => -1})
12
+ end
13
+
14
+ def functions(args=[])
15
+ puts function_map.keys.sort
16
+ end
17
+
18
+ def vars(args=[])
19
+ # remove duplicate variables that are also in the facts hash
20
+ vars = scope.to_hash.delete_if {| key, value | node.facts.values.key?(key) }
21
+ vars['facts'] = 'removed by the puppet-repl' if vars.key?('facts')
22
+ ap 'Facts were removed for easier viewing'
23
+ ap(vars, {:sort_keys => true, :indent => -1})
24
+ end
25
+
26
+ def environment(args=[])
27
+ puts "Puppet Environment: #{puppet_env_name}"
28
+ end
29
+
30
+ def reset(args=[])
31
+ set_scope(nil)
32
+ # initilize scope again
33
+ scope
34
+ set_log_level(log_level)
35
+ end
36
+
37
+ def krt(args=[])
38
+ ap(known_resource_types, {:sort_keys => true, :indent => -1})
39
+ end
40
+
41
+ def play(args=[])
42
+ config = {}
43
+ config[:play] = args.first
44
+ play_back(config)
45
+ end
46
+
47
+ def resources(args=[])
48
+ res = scope.compiler.catalog.resources.map do |res|
49
+ res.to_s
50
+ end
51
+ if !args.first.nil?
52
+ ap res[args.first.to_i]
53
+ else
54
+ puts "Resources not shown in any specific order".warning
55
+ ap res
56
+ end
57
+ end
58
+
59
+ def classes(args=[])
60
+ ap scope.compiler.catalog.classes
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -4,11 +4,20 @@ module PuppetRepl
4
4
  # creates a node object
5
5
  def create_node
6
6
  options = {}
7
- options[:parameters] = facts
8
- options[:facts] = facts
7
+ options[:parameters] = default_facts.values
8
+ options[:facts] = default_facts
9
9
  options[:classes] = []
10
10
  options[:environment] = puppet_environment
11
- Puppet::Node.new(facts[:fqdn], options)
11
+ Puppet::Node.new(default_facts.values['fqdn'], options)
12
+ end
13
+
14
+ # @return [node] puppet node object
15
+ def node
16
+ @node ||= create_node
17
+ end
18
+
19
+ def set_node(value)
20
+ @node = value
12
21
  end
13
22
  end
14
23
  end
@@ -0,0 +1,37 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module Play
4
+
5
+ def play_back(config={})
6
+ if config[:play]
7
+ if config[:play] =~ /^http/
8
+ play_back_url(config[:play])
9
+ elsif File.exists? config[:play]
10
+ play_back_string(File.read(config[:play]))
11
+ else config[:play]
12
+ puts "puppet-repl can't play #{config[:play]}'"
13
+ end
14
+ end
15
+ read_loop
16
+ end
17
+
18
+ def play_back_url(url)
19
+ require 'open-uri'
20
+ require 'net/http'
21
+
22
+ if url[/gist.github.com\/[a-z\d]+$/]
23
+ url += '.txt'
24
+ elsif url[/github.com.*blob/]
25
+ url.sub!('blob', 'raw')
26
+ end
27
+ play_back_string open(url).string
28
+ rescue SocketError
29
+ abort "puppet-repl can't play `#{url}'"
30
+ end
31
+
32
+ def play_back_string(str)
33
+ handle_input(str)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,9 +1,24 @@
1
1
  module PuppetRepl
2
2
  module Support
3
3
  module Scope
4
+
5
+ def set_scope(value)
6
+ @scope = value
7
+ end
8
+
9
+ # @return [Scope] puppet scope object
10
+ def scope
11
+ unless @scope
12
+ do_initialize
13
+ @scope ||= create_scope(node)
14
+ end
15
+ @scope
16
+ end
17
+
4
18
  def create_scope(node)
5
19
  @compiler = create_compiler(node) # creates a new compiler for each scope
6
20
  scope = Puppet::Parser::Scope.new(@compiler)
21
+ # creates a node class
7
22
  scope.source = Puppet::Resource::Type.new(:node, node.name)
8
23
  scope.parent = @compiler.topscope
9
24
  load_lib_dirs
@@ -15,7 +30,7 @@ module PuppetRepl
15
30
 
16
31
  # returns a hash of varaibles that are currently in scope
17
32
  def scope_vars
18
- vars = scope.to_hash.delete_if {| key, value | node.facts.key?(key.to_sym) }
33
+ vars = scope.to_hash.delete_if {| key, value | node.facts.values.key?(key.to_sym) }
19
34
  vars['facts'] = 'removed by the puppet-repl'
20
35
  end
21
36
  end
@@ -13,16 +13,41 @@ module PuppetRepl
13
13
  include PuppetRepl::Support::Scope
14
14
  include PuppetRepl::Support::Functions
15
15
  include PuppetRepl::Support::Node
16
+ include PuppetRepl::Support::InputResponders
17
+ include PuppetRepl::Support::Play
16
18
 
17
- # returns an array of module directories
18
- def module_dirs
19
+ # returns an array of module directories, generally this is the only place
20
+ # to look for puppet code by default. This is read from the puppet configuration
21
+ def default_modules_paths
19
22
  dirs = []
20
23
  do_initialize if Puppet[:codedir].nil?
21
- dirs << File.join(Puppet[:environmentpath],puppet_env_name,'modules') unless Puppet[:environmentpath].empty?
24
+ # add the puppet-repl directory so we can load any defined functions
25
+ dirs << File.join(Puppet[:environmentpath],default_puppet_env_name,'modules') unless Puppet[:environmentpath].empty?
22
26
  dirs << Puppet.settings[:basemodulepath].split(':')
23
27
  dirs.flatten
24
28
  end
25
29
 
30
+ # this is the lib directory of this gem
31
+ # in order to load any puppet functions from this gem we need to add the lib path
32
+ # of this gem
33
+ def puppet_repl_lib_dir
34
+ File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'lib'))
35
+ end
36
+
37
+ # returns all the modules paths defined in the environment
38
+ def modules_paths
39
+ puppet_environment.full_modulepath
40
+ end
41
+
42
+ def initialize_from_scope(value)
43
+ set_scope(value)
44
+ unless value.nil?
45
+ set_environment(value.environment)
46
+ set_node(value.compiler.node)
47
+ set_compiler(value.compiler)
48
+ end
49
+ end
50
+
26
51
  def known_resource_types
27
52
  res = {
28
53
  :hostclasses => scope.known_resource_types.hostclasses.keys,
@@ -46,6 +71,7 @@ module PuppetRepl
46
71
  def do_initialize
47
72
  begin
48
73
  Puppet.initialize_settings
74
+ Puppet[:trusted_node_data] = true
49
75
  rescue
50
76
  # do nothing otherwise calling init twice raises an error
51
77
  end
@@ -53,51 +79,17 @@ module PuppetRepl
53
79
 
54
80
  def puppet_lib_dir
55
81
  # returns something like "/Library/Ruby/Gems/2.0.0/gems/puppet-4.2.2/lib/puppet.rb"
82
+ # this is only useful when returning a namespace with the functions
56
83
  @puppet_lib_dir ||= File.dirname(Puppet.method(:[]).source_location.first)
57
84
  end
58
85
 
59
- # returns either the module name or puppet version
60
- def mod_finder
61
- @mod_finder ||= Regexp.new('\/([\w\-\.]+)\/lib')
62
- end
63
-
64
- def lib_dirs
65
- module_dirs.map do |mod_dir|
66
- Dir["#{mod_dir}/*/lib"].entries
67
- end.flatten
68
- end
69
-
70
- def load_lib_dirs
71
- lib_dirs.each do |lib|
72
- $LOAD_PATH << lib
73
- end
74
- end
75
-
76
86
  # returns a future parser for evaluating code
77
87
  def parser
78
88
  @parser || ::Puppet::Pops::Parser::EvaluatingParser.new
79
89
  end
80
90
 
81
- def compiler
82
- @compiler
83
- end
84
-
85
- # @return [node] puppet node object
86
- def node
87
- @node ||= create_node
88
- end
89
-
90
- # @return [Scope] puppet scope object
91
- def scope
92
- unless @scope
93
- do_initialize
94
- @scope ||= create_scope(node)
95
- end
96
- @scope
97
- end
98
-
99
- def manifests_dir
100
- File.join(Puppet[:environmentpath],puppet_env_name,'manifests')
91
+ def default_manifests_dir
92
+ File.join(Puppet[:environmentpath],default_puppet_env_name,'manifests')
101
93
  end
102
94
 
103
95
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PuppetRepl
2
- VERSION = '0.0.8'
2
+ VERSION = '0.1.0'
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.0.8"
8
+ s.version = "0.1.0"
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-03"
12
+ s.date = "2016-04-13"
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"]
@@ -37,7 +37,9 @@ Gem::Specification.new do |s|
37
37
  "lib/puppet-repl/support/environment.rb",
38
38
  "lib/puppet-repl/support/facts.rb",
39
39
  "lib/puppet-repl/support/functions.rb",
40
+ "lib/puppet-repl/support/input_responders.rb",
40
41
  "lib/puppet-repl/support/node.rb",
42
+ "lib/puppet-repl/support/play.rb",
41
43
  "lib/puppet-repl/support/scope.rb",
42
44
  "lib/version.rb",
43
45
  "puppet-repl.gemspec",
@@ -33,11 +33,30 @@ 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\", \"reset\", \"help\" for more information.\n\n/
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/
37
37
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
38
38
  end
39
39
  end
40
40
 
41
+ describe 'empty' do
42
+ let(:input) do
43
+ ""
44
+ end
45
+ it 'can run' do
46
+ repl_output = ''
47
+ expect{repl.handle_input(input)}.to output(repl_output).to_stdout
48
+ end
49
+ describe 'space' do
50
+ let(:input) do
51
+ " "
52
+ end
53
+ it 'can run' do
54
+ repl_output = ''
55
+ expect{repl.handle_input(input)}.to output(repl_output).to_stdout
56
+ end
57
+ end
58
+ end
59
+
41
60
  describe 'krt' do
42
61
  let(:input) do
43
62
  "krt"
@@ -101,6 +120,7 @@ describe "PuppetRepl" do
101
120
  repl_output = /Puppet::Type::File/
102
121
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
103
122
  end
123
+
104
124
  describe 'loglevel' do
105
125
  it 'has not changed' do
106
126
  repl.handle_input(":set loglevel debug")
@@ -154,6 +174,24 @@ describe "PuppetRepl" do
154
174
  end
155
175
  end
156
176
 
177
+ describe 'print resources' do
178
+ let(:input) do
179
+ 'resources'
180
+ end
181
+ it 'should be able to print resources' do
182
+ expect{repl.handle_input(input)}.to output(/main/).to_stdout
183
+ end
184
+ end
185
+
186
+ describe 'print classes' do
187
+ let(:input) do
188
+ 'resources'
189
+ end
190
+ it 'should be able to print classes' do
191
+ expect{repl.handle_input(input)}.to output(/Settings/).to_stdout
192
+ end
193
+ end
194
+
157
195
  describe 'set' do
158
196
  let(:input) do
159
197
  ":set loglevel debug"
@@ -174,9 +212,13 @@ describe "PuppetRepl" do
174
212
  output = /facts/
175
213
  expect{repl.handle_input(input)}.to output(output).to_stdout
176
214
  end
177
- it 'dispaly local variable' do
178
- repl.handle_input("$var1 = 'value1'")
179
- expect{repl.handle_input(input)}.to output(/var1/).to_stdout
215
+ it 'display local variable' do
216
+ expect{repl.handle_input("$var1 = 'value1'")}.to output(/value1/).to_stdout
217
+ expect{repl.handle_input("$var1")}.to output(/value1/).to_stdout
218
+
219
+ end
220
+ it 'display productname variable' do
221
+ expect{repl.handle_input("$productname")}.to output(/VirtualBox/).to_stdout
180
222
  end
181
223
  end
182
224
 
data/spec/support_spec.rb CHANGED
@@ -55,12 +55,17 @@ describe 'support' do
55
55
  end
56
56
 
57
57
  it 'should return module dirs' do
58
- expect(repl.module_dirs.count).to be >= 1
58
+ expect(repl.modules_paths.count).to be >= 1
59
+ end
60
+
61
+ it 'should return a list of default facts' do
62
+ expect(repl.default_facts.values).to be_instance_of(Hash)
63
+ expect(repl.default_facts.values['fqdn']).to eq('foo.example.com')
59
64
  end
60
65
 
61
66
  it 'should return a list of facts' do
62
- expect(repl.facts).to be_instance_of(Hash)
63
- expect(repl.facts[:fqdn]).to eq('foo.example.com')
67
+ expect(repl.node.facts.values).to be_instance_of(Hash)
68
+ expect(repl.node.facts.values['fqdn']).to eq('foo.example.com')
64
69
  end
65
70
 
66
71
  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.0.8
4
+ version: 0.1.0
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-03 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -108,7 +108,9 @@ files:
108
108
  - lib/puppet-repl/support/environment.rb
109
109
  - lib/puppet-repl/support/facts.rb
110
110
  - lib/puppet-repl/support/functions.rb
111
+ - lib/puppet-repl/support/input_responders.rb
111
112
  - lib/puppet-repl/support/node.rb
113
+ - lib/puppet-repl/support/play.rb
112
114
  - lib/puppet-repl/support/scope.rb
113
115
  - lib/version.rb
114
116
  - puppet-repl.gemspec