molder 0.2.0 → 0.2.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
  SHA256:
3
- metadata.gz: 416984ac32edc7ff37f6d1e6af4452d6e76c06a067ef47d224f06d98e77e4f7b
4
- data.tar.gz: 12793070ad5336d858f8ebe2059088c382f83419e5dfd49ee6378df7c0cc2770
3
+ metadata.gz: 578955563ff2b10bc32a0b3bd32ee0c7b31d72b8808262548ccc46fa10b9cc98
4
+ data.tar.gz: a93de7301be71a8e0313a54a333b536f7029d27e09c79518151af5acbeab50d4
5
5
  SHA512:
6
- metadata.gz: ed68c853eb5586055bea4674204af94018d6e0e4816d63fbd924a90cce11cb5b2899ea451397e6557b1a099ceaa2218d3c3519c6f3a026fca3619f8246cad57b
7
- data.tar.gz: c77e6d30a6e960ace71885e7e804b8c0924cafae972d30fbd54844e4c3f1afe4ddba1a569efa10a6c25bce8442219cdc6804364df2a899937fc344cfea8cbf67
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, the value of environment in the command line would be blank.
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
 
Binary file
@@ -64,6 +64,7 @@ module Molder
64
64
  attributes = attrs.dup
65
65
  attributes.merge!(options.override) if options.override
66
66
  self.templates << ::Molder::Template.new(config: config,
67
+ options: options,
67
68
  name: name,
68
69
  indexes: indexes,
69
70
  command: command,
@@ -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 them') { |_value| options[:dry_run] = true }
143
+ 'Don\'t actually run commands, just print') { |_value| options[:dry_run] = true }
140
144
 
141
145
  opts.on('-v', '--verbose',
142
- 'Print more output') { |_value| options[:verbose] = true }
146
+ 'More verbose output') { |_value| options[:verbose] = true }
143
147
 
144
- opts.on('-b', '--backtrace',
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.blue}
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]'.blue.bold}
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 "Error: #{exception.to_s.bold.red}" if exception
191
- @stderr.puts "Error: #{message.bold.red}" if message
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
 
@@ -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(template)
70
- self.template = 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
- liquid_template.render(attributes, { strict_variables: true }).tap do
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Molder
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  DESCRIPTION = <<-eof
4
4
  Molder is a handy command line tool for generating and running (in parallel,
5
5
  using a pool of processes with a configurable size) a set of related and yet
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: molder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul