puppet-repl 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efa15e795af4973b078852664154fe9e60d9b908
4
- data.tar.gz: a59f074150a899b9e67c59ca9b6874651541b7c4
3
+ metadata.gz: b8b2d91eeef5f922cd54569176f6085199647745
4
+ data.tar.gz: 54320984760c3e54982a9bafda14b5c7742049c5
5
5
  SHA512:
6
- metadata.gz: 174bc1f05d44735c39e55417eb05cd54bb19a6a666572afc46bc025868c3a26f3624ba4d5d691d15e7b4360ac743e0cfb24e53bcf8f77548ea9dd16e0ce4234f
7
- data.tar.gz: d3b20b61ea361187b5cf646b5336a3f58207f54ed40c39b3dde5582dddeefca7e87a925f0e04f99b2046e6c5aea50e056dedb23ed5545f43968092e40e52befc
6
+ metadata.gz: 6f289d12177afa7d7888699f6b1e8afa65b0ada85bc1969019365af520289404969e64f8654e7ed019a7161c8d1b7278b2ef9f863740862f548e226cd2a9e267
7
+ data.tar.gz: 1e7434a150bb7543d64f19d26c538d67527e47856a505e43dd3795812627732e6f2a9da9b30cf6948a4f1ac7500ebf12228bca6c5cab2aa2e7fb2b104cc65f8f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.8
2
+ * adds ability to list currently loaded classes
3
+ * adds formatted output using awesome print
4
+ * adds verbose type output when creating resources
1
5
  ## 0.0.7
2
6
  * Added ability to list scope variables
3
7
  ## 0.0.6
data/Gemfile.lock CHANGED
@@ -27,7 +27,7 @@ GEM
27
27
  multi_json (>= 1.7.5, < 2.0)
28
28
  oauth2
29
29
  hashie (3.4.3)
30
- hiera (3.0.6)
30
+ hiera (1.3.4)
31
31
  json_pure
32
32
  highline (1.7.8)
33
33
  jeweler (2.0.1)
@@ -61,9 +61,9 @@ GEM
61
61
  coderay (~> 1.1.0)
62
62
  method_source (~> 0.8.1)
63
63
  slop (~> 3.4)
64
- puppet (4.3.2)
65
- facter (> 2.0, < 4)
66
- hiera (>= 2.0, < 4)
64
+ puppet (3.8.5)
65
+ facter (> 1.6, < 3)
66
+ hiera (~> 1.0)
67
67
  json_pure
68
68
  rack (1.6.4)
69
69
  rake (10.5.0)
data/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  - [Load path](#load-path)
9
9
  - [Usage](#usage)
10
10
  - [Using Variables](#using-variables)
11
+ - [Listing variables](#listing-variables)
11
12
  - [Using functions](#using-functions)
12
13
  - [Duplicate resource error](#duplicate-resource-error)
13
14
  - [Setting the puppet log level](#setting-the-puppet-log-level)
@@ -46,17 +47,18 @@ and try to enforce the catalog. This has a few side affects.
46
47
  Example Usage
47
48
  ```
48
49
  MacBook-Pro-2/tmp % prepl
49
- Puppet Version: 4.2.2
50
- Puppet Repl Version: 0.0.1
50
+ Ruby Version: 2.0.0
51
+ Puppet Version: 3.8.5
52
+ Puppet Repl Version: 0.0.7
51
53
  Created by: NWOps <corey@nwops.io>
52
- Type "exit", "functions", "types", "reset", "help" for more information.
54
+ Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more information.
53
55
 
54
- >> file{'/tmp/test2': ensure => present}
55
- => File['/tmp/test2']
56
56
  >> ['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }
57
- =>
58
- /tmp/test3
59
- /tmp/test4
57
+ => [
58
+ [0] "/tmp/test3",
59
+ [1] "/tmp/test4"
60
+ ]
61
+ >>
60
62
 
61
63
  ```
62
64
 
@@ -64,16 +66,37 @@ Type "exit", "functions", "types", "reset", "help" for more information.
64
66
 
65
67
  ```
66
68
  MacBook-Pro-2/tmp % prepl
67
- Puppet Version: 4.2.2
68
- Puppet Repl Version: 0.0.1
69
+ Ruby Version: 2.0.0
70
+ Puppet Version: 3.8.5
71
+ Puppet Repl Version: 0.0.7
69
72
  Created by: NWOps <corey@nwops.io>
70
- Type "exit", "functions", "types", "reset", "help" for more information.
73
+ Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more information.
71
74
 
72
- >> $config_file = '/etc/httpd/httpd.conf'
73
- => /etc/httpd/httpd.conf
74
- >> file{$config_file: ensure => present, content => 'hello'}
75
- => File['/etc/httpd/httpd.conf']
76
75
  >>
76
+
77
+ >> $config_file = '/etc/httpd/httpd.conf'
78
+ => "/etc/httpd/httpd.conf"
79
+ >> file{$config_file: ensure => present, content => 'hello'}
80
+ => Puppet::Type::File {
81
+ path => "/etc/httpd/httpd.conf",
82
+ provider => posix,
83
+ ensure => present,
84
+ content => "{md5}5d41402abc4b2a76b9719d911017c592",
85
+ checksum => nil,
86
+ backup => "puppet",
87
+ replace => true,
88
+ links => manage,
89
+ purge => false,
90
+ sourceselect => first,
91
+ show_diff => true,
92
+ validate_replacement => "%",
93
+ source_permissions => use,
94
+ selinux_ignore_defaults => false,
95
+ loglevel => notice,
96
+ name => "/etc/httpd/httpd.conf",
97
+ title => "/etc/httpd/httpd.conf"
98
+ }
99
+ >>
77
100
  ```
78
101
  ### Listing variables
79
102
  To see the current variables in the scope use the `vars` keyword.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -2,39 +2,70 @@ require 'puppet'
2
2
  require 'readline'
3
3
  require 'json'
4
4
  require_relative 'support'
5
+
5
6
  module PuppetRepl
6
7
  class Cli
7
8
  include PuppetRepl::Support
8
9
 
10
+ attr_accessor :settings, :log_level
11
+
12
+ def initialize
13
+ @log_level = 'notice'
14
+ end
15
+
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
22
+ end
23
+
9
24
  def puppet_eval(input)
10
- begin
11
- parser.evaluate_string(scope, input)
12
- rescue ArgumentError => e
13
- e.message
14
- rescue Puppet::ParseErrorWithIssue => e
15
- e.message
16
- rescue Exception => e
17
- e.message
25
+ parser.evaluate_string(scope, input)
26
+ end
27
+
28
+ def to_resource_declaration(type)
29
+ res = scope.catalog.resource(type.type_name, type.title)
30
+ res.to_ral
31
+ end
32
+
33
+ # ruturns a formatted array
34
+ def expand_resource_type(types)
35
+ output = [types].flatten.map do |t|
36
+ if t.class.to_s == 'Puppet::Pops::Types::PResourceType'
37
+ to_resource_declaration(t)
38
+ else
39
+ t
40
+ end
18
41
  end
42
+ output
19
43
  end
20
44
 
21
45
  def normalize_output(result)
22
46
  if result.instance_of?(Array)
23
- if result.count == 1
24
- return result.first
47
+ output = expand_resource_type(result)
48
+ if output.count == 1
49
+ return output.first
25
50
  end
51
+ return output
26
52
  end
27
53
  result
28
54
  end
29
55
 
56
+ def set_log_level(level)
57
+ Puppet::Util::Log.level = level.to_sym
58
+ Puppet::Util::Log.newdestination(:console)
59
+ end
60
+
30
61
  def handle_set(input)
31
62
  args = input.split(' ')
32
63
  args.shift # throw away the set
33
64
  case args.shift
34
65
  when /loglevel/
35
66
  if level = args.shift
36
- Puppet::Util::Log.level = level.to_sym
37
- Puppet::Util::Log.newdestination(:console)
67
+ @log_level = level
68
+ set_log_level(level)
38
69
  puts "loglevel #{Puppet::Util::Log.level} is set"
39
70
  end
40
71
  end
@@ -60,16 +91,40 @@ module PuppetRepl
60
91
  ap(vars, {:sort_keys => true, :indent => -1})
61
92
  when 'environment'
62
93
  puts "Puppet Environment: #{puppet_env_name}"
94
+ when 'vars'
95
+ ap(scope.to_hash, {:sort_keys => true, :indent => 0})
63
96
  when 'exit'
64
97
  exit 0
65
98
  when 'reset'
66
99
  @scope = nil
67
- when 'current_resources'
68
- compiler.known_resource_types
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})
69
105
  else
70
- result = puppet_eval(input)
71
- @last_item = result
72
- puts(" => #{normalize_output(result)}")
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)
115
+ 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
+ end
73
128
  end
74
129
  end
75
130
 
@@ -79,7 +134,7 @@ Ruby Version: #{RUBY_VERSION}
79
134
  Puppet Version: #{Puppet.version}
80
135
  Puppet Repl Version: #{PuppetRepl::VERSION}
81
136
  Created by: NWOps <corey@nwops.io>
82
- Type "exit", "functions", "vars", "facts", "reset", "help" for more information.
137
+ Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more information.
83
138
 
84
139
  EOT
85
140
  end
@@ -0,0 +1,11 @@
1
+ require 'tempfile'
2
+
3
+ module PuppetRepl
4
+ module Support
5
+ module Compilier
6
+ def create_compiler(node)
7
+ Puppet::Parser::Compiler.new(node)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module Environment
4
+ # creates a puppet environment given a module path and environment name
5
+ # this is cached
6
+ def puppet_environment
7
+ unless @puppet_environment
8
+ do_initialize
9
+ @puppet_environment = Puppet::Node::Environment.create(
10
+ puppet_env_name,
11
+ module_dirs,
12
+ manifests_dir
13
+ )
14
+ end
15
+ @puppet_environment
16
+ end
17
+
18
+ # the cached name of the environment
19
+ def puppet_env_name
20
+ @penv ||= ENV['PUPPET_ENV'] || Puppet[:environment]
21
+ end
22
+
23
+ # currently this is not being used
24
+ def environment_loaders
25
+ name = compiler.loaders.public_environment_loader.loader_name
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module Facts
4
+ # in the future we will want to grab real facts from real systems via puppetdb
5
+ # or enc data
6
+ def facterdb_filter
7
+ 'operatingsystem=RedHat and operatingsystemrelease=/^7/ and architecture=x86_64 and facterversion=/^2.4\./'
8
+ end
9
+
10
+ # uses facterdb (cached facts) and retrives the facts given a filter
11
+ def facts
12
+ unless @facts
13
+ @facts ||= FacterDB.get_facts(facterdb_filter).first
14
+ end
15
+ @facts
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module Functions
4
+ # returns a array of function files
5
+ def function_files
6
+ search_dirs = lib_dirs.map do |lib_dir|
7
+ [File.join(lib_dir, 'puppet', 'functions', '**', '*.rb'),
8
+ File.join(lib_dir, 'functions', '**', '*.rb'),
9
+ File.join(lib_dir, 'puppet', 'parser', 'functions', '*.rb')
10
+ ]
11
+ end
12
+ # add puppet lib directories
13
+ search_dirs << [File.join(puppet_lib_dir, 'puppet', 'functions', '**', '*.rb'),
14
+ File.join(puppet_lib_dir, 'puppet', 'parser', 'functions', '*.rb')
15
+ ]
16
+ Dir.glob(search_dirs.flatten)
17
+ end
18
+
19
+ # returns a map of functions
20
+ def function_map
21
+ unless @functions
22
+ do_initialize
23
+ @functions = {}
24
+ function_files.each do |file|
25
+ obj = {}
26
+ name = File.basename(file, '.rb')
27
+ obj[:name] = name
28
+ obj[:parent] = mod_finder.match(file)[1]
29
+ @functions["#{obj[:parent]}::#{name}"] = obj
30
+ end
31
+ end
32
+ @functions
33
+ end
34
+
35
+ # def functions
36
+ # @functions = []
37
+ # @functions << compiler.loaders.static_loader.loaded.keys.find_all {|l| l.type == :function}
38
+ # end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module Node
4
+ # creates a node object
5
+ def create_node
6
+ options = {}
7
+ options[:parameters] = facts
8
+ options[:facts] = facts
9
+ options[:classes] = []
10
+ options[:environment] = puppet_environment
11
+ Puppet::Node.new(facts[:fqdn], options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module PuppetRepl
2
+ module Support
3
+ module Scope
4
+ def create_scope(node)
5
+ @compiler = create_compiler(node) # creates a new compiler for each scope
6
+ scope = Puppet::Parser::Scope.new(@compiler)
7
+ scope.source = Puppet::Resource::Type.new(:node, node.name)
8
+ scope.parent = @compiler.topscope
9
+ load_lib_dirs
10
+ # compiling will load all the facts into the scope
11
+ # without this step facts will not get resolved
12
+ scope.compiler.compile # this will load everything into the scope
13
+ scope
14
+ end
15
+
16
+ # returns a hash of varaibles that are currently in scope
17
+ def scope_vars
18
+ vars = scope.to_hash.delete_if {| key, value | node.facts.key?(key.to_sym) }
19
+ vars['facts'] = 'removed by the puppet-repl'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,17 +1,47 @@
1
1
  require 'puppet/pops'
2
2
  require 'facterdb'
3
+ # load all the generators found in the generators directory
4
+ Dir.glob(File.join(File.dirname(__FILE__),'support', '*.rb')).each do |file|
5
+ require_relative File.join('support', File.basename(file, '.rb'))
6
+ end
3
7
 
4
8
  module PuppetRepl
5
9
  module Support
10
+ include PuppetRepl::Support::Compilier
11
+ include PuppetRepl::Support::Environment
12
+ include PuppetRepl::Support::Facts
13
+ include PuppetRepl::Support::Scope
14
+ include PuppetRepl::Support::Functions
15
+ include PuppetRepl::Support::Node
6
16
 
7
17
  # returns an array of module directories
8
18
  def module_dirs
9
19
  dirs = []
20
+ do_initialize if Puppet[:codedir].nil?
10
21
  dirs << File.join(Puppet[:environmentpath],puppet_env_name,'modules') unless Puppet[:environmentpath].empty?
11
22
  dirs << Puppet.settings[:basemodulepath].split(':')
12
23
  dirs.flatten
13
24
  end
14
25
 
26
+ def known_resource_types
27
+ res = {
28
+ :hostclasses => scope.known_resource_types.hostclasses.keys,
29
+ :definitions => scope.known_resource_types.definitions.keys,
30
+ :nodes => scope.known_resource_types.nodes.keys,
31
+ }
32
+ if sites = scope.known_resource_types.instance_variable_get(:@sites)
33
+ res.merge!(:sites => scope.known_resource_types.instance_variable_get(:@sites).first)
34
+ end
35
+ if scope.known_resource_types.respond_to?(:applications)
36
+ res.merge!(:applications => scope.known_resource_types.applications.keys)
37
+ end
38
+ # some versions of puppet do not support capabilities
39
+ if scope.known_resource_types.respond_to?(:capability_mappings)
40
+ res.merge!(:capability_mappings => scope.known_resource_types.capability_mappings.keys)
41
+ end
42
+ res
43
+ end
44
+
15
45
  # this is required in order to load things only when we need them
16
46
  def do_initialize
17
47
  begin
@@ -26,42 +56,11 @@ module PuppetRepl
26
56
  @puppet_lib_dir ||= File.dirname(Puppet.method(:[]).source_location.first)
27
57
  end
28
58
 
29
- # returns a array of function files
30
- def function_files
31
- search_dirs = lib_dirs.map do |lib_dir|
32
- [File.join(lib_dir, 'puppet', 'functions', '**', '*.rb'),
33
- File.join(lib_dir, 'functions', '**', '*.rb'),
34
- File.join(lib_dir, 'puppet', 'parser', 'functions', '*.rb')
35
- ]
36
- end
37
- # add puppet lib directories
38
- search_dirs << [File.join(puppet_lib_dir, 'puppet', 'functions', '**', '*.rb'),
39
- File.join(puppet_lib_dir, 'puppet', 'parser', 'functions', '*.rb')
40
- ]
41
- Dir.glob(search_dirs.flatten)
42
- end
43
-
44
59
  # returns either the module name or puppet version
45
60
  def mod_finder
46
61
  @mod_finder ||= Regexp.new('\/([\w\-\.]+)\/lib')
47
62
  end
48
63
 
49
- # returns a map of functions
50
- def function_map
51
- unless @functions
52
- do_initialize
53
- @functions = {}
54
- function_files.each do |file|
55
- obj = {}
56
- name = File.basename(file, '.rb')
57
- obj[:name] = name
58
- obj[:parent] = mod_finder.match(file)[1]
59
- @functions["#{obj[:parent]}::#{name}"] = obj
60
- end
61
- end
62
- @functions
63
- end
64
-
65
64
  def lib_dirs
66
65
  module_dirs.map do |mod_dir|
67
66
  Dir["#{mod_dir}/*/lib"].entries
@@ -79,82 +78,20 @@ module PuppetRepl
79
78
  @parser || ::Puppet::Pops::Parser::EvaluatingParser.new
80
79
  end
81
80
 
82
- # the cached name of the environment
83
- def puppet_env_name
84
- @penv ||= ENV['PUPPET_ENV'] || Puppet[:environment]
85
- end
86
-
87
- # creates a puppet environment given a module path and environment name
88
- # this is cached
89
- def puppet_environment
90
- unless @puppet_environment
91
- do_initialize
92
- @puppet_environment = Puppet::Node::Environment.create(
93
- puppet_env_name,
94
- module_dirs,
95
- manifests_dir
96
- )
97
- end
98
- @puppet_environment
99
- end
100
-
101
- # def functions
102
- # @functions = []
103
- # @functions << compiler.loaders.static_loader.loaded.keys.find_all {|l| l.type == :function}
104
- # end
105
-
106
- def environment_loaders
107
- name = compiler.loaders.public_environment_loader.loader_name
108
- end
109
-
110
81
  def compiler
111
82
  @compiler
112
83
  end
113
84
 
85
+ # @return [node] puppet node object
114
86
  def node
115
87
  @node ||= create_node
116
88
  end
117
89
 
118
- def create_scope
119
- @compiler = create_compiler(node) # creates a new compiler for each scope
120
- scope = Puppet::Parser::Scope.new(compiler)
121
- scope.source = Puppet::Resource::Type.new(:node, node.name)
122
- scope.parent = compiler.topscope
123
- load_lib_dirs
124
- compiler.compile # this will load everything into the scope
125
- scope
126
- end
127
-
128
- def create_compiler(node)
129
- Puppet::Parser::Compiler.new(node)
130
- end
131
-
132
- def facterdb_filter
133
- 'operatingsystem=RedHat and operatingsystemrelease=/^7/ and architecture=x86_64 and facterversion=/^2.4\./'
134
- end
135
-
136
- # uses facterdb (cached facts) and retrives the facts given a filter
137
- def facts
138
- unless @facts
139
- @facts ||= FacterDB.get_facts(facterdb_filter).first
140
- end
141
- @facts
142
- end
143
-
144
- # creates a node object
145
- def create_node
146
- options = {}
147
- options[:parameters] = facts
148
- options[:facts] = facts
149
- options[:classes] = []
150
- options[:environment] = puppet_environment
151
- Puppet::Node.new(facts[:fqdn], options)
152
- end
153
-
90
+ # @return [Scope] puppet scope object
154
91
  def scope
155
92
  unless @scope
156
93
  do_initialize
157
- @scope ||= create_scope
94
+ @scope ||= create_scope(node)
158
95
  end
159
96
  @scope
160
97
  end
@@ -165,4 +102,3 @@ module PuppetRepl
165
102
 
166
103
  end
167
104
  end
168
- #scope.environment.known_resource_types
data/lib/puppet-repl.rb CHANGED
@@ -2,3 +2,19 @@ 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
+
6
+ # monkey patch in some color effects string methods
7
+ class String
8
+ def red; "\033[31m#{self}\033[0m" end
9
+ def green; "\033[32m#{self}\033[0m" end
10
+ def cyan; "\033[36m#{self}\033[0m" end
11
+ def yellow; "\033[33m#{self}\033[0m" end
12
+ def warning; yellow end
13
+ def fatal; red end
14
+ def info; green end
15
+
16
+ def camel_case
17
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
18
+ split('_').map(&:capitalize).join
19
+ end
20
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PuppetRepl
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
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.7"
8
+ s.version = "0.0.8"
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-02"
12
+ s.date = "2016-04-03"
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"]
@@ -33,8 +33,15 @@ Gem::Specification.new do |s|
33
33
  "lib/puppet-repl.rb",
34
34
  "lib/puppet-repl/cli.rb",
35
35
  "lib/puppet-repl/support.rb",
36
+ "lib/puppet-repl/support/compiler.rb",
37
+ "lib/puppet-repl/support/environment.rb",
38
+ "lib/puppet-repl/support/facts.rb",
39
+ "lib/puppet-repl/support/functions.rb",
40
+ "lib/puppet-repl/support/node.rb",
41
+ "lib/puppet-repl/support/scope.rb",
36
42
  "lib/version.rb",
37
43
  "puppet-repl.gemspec",
44
+ "spec/fixtures/environments/production/manifests/site.pp",
38
45
  "spec/puppet-repl_spec.rb",
39
46
  "spec/spec_helper.rb",
40
47
  "spec/support_spec.rb"
@@ -0,0 +1 @@
1
+ fail('test_error')
@@ -6,16 +6,44 @@ describe "PuppetRepl" do
6
6
  "service{'httpd': ensure => running}"
7
7
  end
8
8
 
9
+ before(:each) do
10
+ repl.handle_input('reset')
11
+ end
12
+
9
13
  let(:repl) do
10
14
  PuppetRepl::Cli.new
11
15
  end
12
16
 
17
+ let(:input) do
18
+ "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
19
+ end
20
+
21
+ let(:resource_types) do
22
+ repl.parser.evaluate_string(repl.scope, input)
23
+ end
24
+
25
+ describe 'returns a array of resource_types' do
26
+ it 'returns resource type' do
27
+ expect(resource_types.first.class.to_s).to eq('Puppet::Pops::Types::PResourceType')
28
+ end
29
+ end
30
+
13
31
  describe 'help' do
14
32
  let(:input) do
15
33
  'help'
16
34
  end
17
35
  it 'can show the help screen' do
18
- 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\", \"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\", \"reset\", \"help\" for more information.\n\n/
37
+ expect{repl.handle_input(input)}.to output(repl_output).to_stdout
38
+ end
39
+ end
40
+
41
+ describe 'krt' do
42
+ let(:input) do
43
+ "krt"
44
+ end
45
+ it 'can run' do
46
+ repl_output = /hostclasses/
19
47
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
20
48
  end
21
49
  end
@@ -25,7 +53,7 @@ describe "PuppetRepl" do
25
53
  "$file_path = '/tmp/test2.txt'"
26
54
  end
27
55
  it 'can process a variable' do
28
- repl_output = " => /tmp/test2.txt\n"
56
+ repl_output = " => \e[0;33m\"/tmp/test2.txt\"\e[0m\n"
29
57
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
30
58
  end
31
59
  end
@@ -35,7 +63,7 @@ describe "PuppetRepl" do
35
63
  "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
36
64
  end
37
65
  it 'can process a resource' do
38
- repl_output = " => File['/tmp/test2.txt']\n"
66
+ repl_output = /Puppet::Type::File/
39
67
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
40
68
  end
41
69
  end
@@ -45,7 +73,17 @@ describe "PuppetRepl" do
45
73
  "Service{"
46
74
  end
47
75
  it 'can process' do
48
- repl_output = " => Syntax error at end of file\n"
76
+ repl_output = " => \e[31mSyntax error at end of file\e[0m\n"
77
+ expect{repl.handle_input(input)}.to output(repl_output).to_stdout
78
+ end
79
+ end
80
+
81
+ describe 'bad resources' do
82
+ let(:input) do
83
+ "file{'/tmp/test': ensure => present, mode => 755}"
84
+ end
85
+ xit 'can process' do #this fails with puppet 3.8 and passes with others
86
+ repl_output = /must be a string/
49
87
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
50
88
  end
51
89
  end
@@ -60,7 +98,27 @@ describe "PuppetRepl" do
60
98
 
61
99
  it 'can process a each block' do
62
100
  repl.handle_input('reset')
63
- repl_output = " => File['/tmp/reset']\n"
101
+ repl_output = /Puppet::Type::File/
102
+ expect{repl.handle_input(input)}.to output(repl_output).to_stdout
103
+ end
104
+ describe 'loglevel' do
105
+ it 'has not changed' do
106
+ repl.handle_input(":set loglevel debug")
107
+ expect(Puppet::Util::Log.level).to eq(:debug)
108
+ expect(Puppet::Util::Log.destinations[:console].name).to eq(:console)
109
+ repl.handle_input('reset')
110
+ expect(Puppet::Util::Log.level).to eq(:debug)
111
+ expect(Puppet::Util::Log.destinations[:console].name).to eq(:console)
112
+ end
113
+ end
114
+ end
115
+
116
+ describe 'map block' do
117
+ let(:input) do
118
+ "['/tmp/test3', '/tmp/test4'].map |String $path| { file{$path: ensure => present} }"
119
+ end
120
+ it 'can process a each block' do
121
+ repl_output = /Puppet::Type::File/
64
122
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
65
123
  end
66
124
  end
@@ -69,8 +127,10 @@ describe "PuppetRepl" do
69
127
  let(:input) do
70
128
  "['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }"
71
129
  end
130
+ let(:repl_output) do
131
+ " => [\n \e[1;37m[0] \e[0m\e[0;33m\"/tmp/test3\"\e[0m,\n \e[1;37m[1] \e[0m\e[0;33m\"/tmp/test4\"\e[0m\n]\n"
132
+ end
72
133
  it 'can process a each block' do
73
- repl_output = " => [\"/tmp/test3\", \"/tmp/test4\"]\n"
74
134
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
75
135
  end
76
136
  end
@@ -80,7 +140,7 @@ describe "PuppetRepl" do
80
140
  "$::fqdn"
81
141
  end
82
142
  it 'should be able to resolve fqdn' do
83
- repl_output = " => foo.example.com\n"
143
+ repl_output = " => \e[0;33m\"foo.example.com\"\e[0m\n"
84
144
  expect{repl.handle_input(input)}.to output(repl_output).to_stdout
85
145
  end
86
146
  end
@@ -125,14 +185,13 @@ describe "PuppetRepl" do
125
185
  "md5('hello')"
126
186
  end
127
187
  it 'execute md5' do
128
- sum = " => 5d41402abc4b2a76b9719d911017c592\n"
188
+ sum = " => \e[0;33m\"5d41402abc4b2a76b9719d911017c592\"\e[0m\n"
129
189
  expect{repl.handle_input(input)}.to output(sum).to_stdout
130
190
  end
131
191
  it 'execute swapcase' do
132
- output = " => HELLO\n"
192
+ output = /HELLO/
133
193
  expect{repl.handle_input("swapcase('hello')")}.to output(output).to_stdout
134
194
  end
135
195
 
136
196
  end
137
-
138
197
  end
data/spec/spec_helper.rb CHANGED
@@ -35,6 +35,13 @@ end
35
35
  #
36
36
  # install_stdlib
37
37
 
38
- RSpec.configure do |config|
38
+ def fixtures_dir
39
+ File.join(File.dirname(__FILE__), 'fixtures')
40
+ end
39
41
 
42
+ def environments_dir
43
+ File.join(fixtures_dir, 'environments')
44
+ end
45
+
46
+ RSpec.configure do |config|
40
47
  end
data/spec/support_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
-
2
+ require 'tempfile'
3
3
 
4
4
  describe 'support' do
5
5
 
@@ -15,6 +15,27 @@ describe 'support' do
15
15
  repl.mod_finder.match(repl.puppet_lib_dir)[1]
16
16
  end
17
17
 
18
+ let(:manifest_file) do
19
+ file = File.open('/tmp/repl_puppet_manifest.pp', 'w') do |f|
20
+ f.write(manifest_code)
21
+ end
22
+ '/tmp/repl_puppet_manifest.pp'
23
+ end
24
+
25
+ let(:manifest_code) do
26
+ <<-EOF
27
+ file{'/tmp/test.txt': ensure => absent } \n
28
+ notify{'hello_there':} \n
29
+ service{'httpd': ensure => running}\n
30
+
31
+ EOF
32
+
33
+ end
34
+
35
+ after(:each) do
36
+ #manifest_file.close
37
+ end
38
+
18
39
  context '#function_map' do
19
40
 
20
41
  it 'should list functions' do
@@ -42,6 +63,4 @@ describe 'support' do
42
63
  expect(repl.facts[:fqdn]).to eq('foo.example.com')
43
64
  end
44
65
 
45
-
46
-
47
66
  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.7
4
+ version: 0.0.8
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-02 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -104,8 +104,15 @@ files:
104
104
  - lib/puppet-repl.rb
105
105
  - lib/puppet-repl/cli.rb
106
106
  - lib/puppet-repl/support.rb
107
+ - lib/puppet-repl/support/compiler.rb
108
+ - lib/puppet-repl/support/environment.rb
109
+ - lib/puppet-repl/support/facts.rb
110
+ - lib/puppet-repl/support/functions.rb
111
+ - lib/puppet-repl/support/node.rb
112
+ - lib/puppet-repl/support/scope.rb
107
113
  - lib/version.rb
108
114
  - puppet-repl.gemspec
115
+ - spec/fixtures/environments/production/manifests/site.pp
109
116
  - spec/puppet-repl_spec.rb
110
117
  - spec/spec_helper.rb
111
118
  - spec/support_spec.rb