molder 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +1 -1
- data/docs/molder-cli.png +0 -0
- data/lib/molder/app.rb +1 -0
- data/lib/molder/cli.rb +18 -8
- data/lib/molder/renderer.rb +10 -4
- data/lib/molder/template.rb +4 -3
- data/lib/molder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 578955563ff2b10bc32a0b3bd32ee0c7b31d72b8808262548ccc46fa10b9cc98
|
4
|
+
data.tar.gz: a93de7301be71a8e0313a54a333b536f7029d27e09c79518151af5acbeab50d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be4f718a26b806627ba2ef00a01f1c44df635dbb03ea1a007e4aaedaffb38a243d94593e84bd0d5a652f46b8e600da04da168b704708acc1f7e316f4b5b24b3a
|
7
|
+
data.tar.gz: 5abe1844e966d7c0581ef58ba4597e861c5b4a9f9a3ae9a6b148d8796cd43adafe07d92b722572172eb06652109aa599b9578fe1014c4fc9d40d042872b79b92
|
data/README.md
CHANGED
@@ -169,7 +169,7 @@ Let's understand this command:
|
|
169
169
|
|
170
170
|
* multiple template names can be separated by a slash, as seen here.
|
171
171
|
|
172
|
-
* next we pass `-a environment=production` — notice that our provision command defined in the template uses `{{ environment }}` token, even though no such attribute is defined in any of the templates. if we do not supply this argument,
|
172
|
+
* next we pass `-a environment=production` — notice that our provision command defined in the template uses `{{ environment }}` token, even though no such attribute is defined in any of the templates. if we do not supply this argument, molder will thrown an exception, because blank attributes are not allowed.
|
173
173
|
|
174
174
|
* Note that you can pass multiple attributes, separated by a slash, like so: `-a environment=production/flavor=c5.4xlarge`
|
175
175
|
|
data/docs/molder-cli.png
CHANGED
Binary file
|
data/lib/molder/app.rb
CHANGED
data/lib/molder/cli.rb
CHANGED
@@ -132,20 +132,30 @@ module Molder
|
|
132
132
|
'The default is the number of CPU cores', ' '
|
133
133
|
) { |value| options[:max_processes] = value.to_i }
|
134
134
|
|
135
|
+
opts.on('-b', '--allow-blanks',
|
136
|
+
'Instead of throwing error when attribute',
|
137
|
+
'is nil, replace it with a blank', ' ') { |_value| options[:blank] = true }
|
138
|
+
|
135
139
|
opts.on('-l', '--log-dir [dir]',
|
136
140
|
'Folder where STDOUT of the commands is saved') { |value| options[:log_dir] = value }
|
137
141
|
|
138
142
|
opts.on('-n', '--dry-run',
|
139
|
-
'Don\'t actually run commands, just print
|
143
|
+
'Don\'t actually run commands, just print') { |_value| options[:dry_run] = true }
|
140
144
|
|
141
145
|
opts.on('-v', '--verbose',
|
142
|
-
'
|
146
|
+
'More verbose output') { |_value| options[:verbose] = true }
|
143
147
|
|
144
|
-
opts.on('-
|
148
|
+
opts.on('-d', '--debug',
|
145
149
|
'Show error stack trace if available') { |_value| options[:backtrace] = true }
|
146
150
|
|
151
|
+
opts.on('-V', '--version',
|
152
|
+
'Show version') do
|
153
|
+
@stdout.puts Molder::VERSION
|
154
|
+
options[:help] = true
|
155
|
+
end
|
156
|
+
|
147
157
|
opts.on('-h', '--help',
|
148
|
-
'Show help') do
|
158
|
+
'Show help', ' ') do
|
149
159
|
@stdout.puts opts
|
150
160
|
options[:help] = true
|
151
161
|
end
|
@@ -163,10 +173,10 @@ module Molder
|
|
163
173
|
|
164
174
|
#{'USAGE'.bold.yellow}
|
165
175
|
#{'# shorthand usage - combine multiple templates with a slash:'.bold.black}
|
166
|
-
#{'molder [-c config.yml] command template1[n1..n2]/... [options]'.bold.
|
176
|
+
#{'molder [-c config.yml] command template1[n1..n2]/... [options]'.bold.green}
|
167
177
|
|
168
178
|
#{'# alternatively, use -t and -i CLI options:'.bold.black}
|
169
|
-
#{'molder [-c config.yml] command -t template -i index [options]'.
|
179
|
+
#{'molder [-c config.yml] command -t template -i index [options]'.green.bold}
|
170
180
|
|
171
181
|
#{'EXAMPLES'.bold.yellow}
|
172
182
|
#{'# The following commands assume YAML file is in the default location:'.bold.black}
|
@@ -187,8 +197,8 @@ module Molder
|
|
187
197
|
if options[:backtrace] && exception.backtrace
|
188
198
|
@stderr.puts exception.backtrace.reverse.join("\n").yellow.italic
|
189
199
|
end
|
190
|
-
@stderr.puts "
|
191
|
-
@stderr.puts "
|
200
|
+
@stderr.puts ' • ERROR • '.white.on.red + " #{exception.to_s.bold.red}" if exception
|
201
|
+
@stderr.puts ' • ERROR • '.white.on.red + " #{message.bold.red}" if message
|
192
202
|
@kernel.exit(1)
|
193
203
|
end
|
194
204
|
|
data/lib/molder/renderer.rb
CHANGED
@@ -63,18 +63,24 @@ module Molder
|
|
63
63
|
|
64
64
|
MAX_RECURSIONS = 100
|
65
65
|
|
66
|
-
attr_accessor :template
|
66
|
+
attr_accessor :template, :render_opts
|
67
67
|
|
68
68
|
# Create Renderer object, while storing and auto-expanding params.
|
69
|
-
def initialize(
|
70
|
-
self.template
|
69
|
+
def initialize(template_string, options = {})
|
70
|
+
self.template = template_string
|
71
|
+
self.render_opts = if options[:blank]
|
72
|
+
{}
|
73
|
+
else
|
74
|
+
{ strict_variables: true }
|
75
|
+
end
|
71
76
|
end
|
72
77
|
|
73
78
|
# Render given content using expanded params.
|
74
79
|
def render(params)
|
75
80
|
attributes = expand_arguments(Hashie.stringify_keys(params.to_h))
|
76
81
|
liquid_template = Liquid::Template.parse(template)
|
77
|
-
|
82
|
+
|
83
|
+
liquid_template.render(attributes, **render_opts).tap do
|
78
84
|
unless liquid_template.errors.empty?
|
79
85
|
raise LiquidTemplateError, "#{liquid_template.errors.map(&:message).join("\n")}"
|
80
86
|
end
|
data/lib/molder/template.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'molder/renderer'
|
2
2
|
module Molder
|
3
3
|
class Template
|
4
|
-
attr_accessor :config, :name, :attributes, :indexes, :command
|
4
|
+
attr_accessor :config, :name, :attributes, :indexes, :command, :options
|
5
5
|
|
6
|
-
def initialize(config:, name:, indexes:, attributes: {}, command:)
|
6
|
+
def initialize(config:, name:, indexes:, attributes: {}, command:, options: {})
|
7
7
|
self.config = config
|
8
8
|
self.name = name
|
9
9
|
self.indexes = indexes
|
10
10
|
self.command = command
|
11
|
+
self.options = options
|
11
12
|
self.attributes = self.class.normalize(attributes)
|
12
13
|
end
|
13
14
|
|
@@ -15,7 +16,7 @@ module Molder
|
|
15
16
|
indexes.map do |i|
|
16
17
|
self.attributes[:number] = i
|
17
18
|
self.attributes[:formatted_number] = sprintf(config.global.index_format, i)
|
18
|
-
::Molder::Renderer.new(command.args).render(attributes.dup).tap do |cmd|
|
19
|
+
::Molder::Renderer.new(command.args, options).render(attributes.dup).tap do |cmd|
|
19
20
|
yield(cmd) if block_given?
|
20
21
|
end
|
21
22
|
end
|
data/lib/molder/version.rb
CHANGED