aws-must 0.0.12 → 0.0.13
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 +12 -14
- data/bin/aws-must.rb +77 -16
- data/lib/aws-must/template.rb +56 -26
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4df0abe6aafa2e3145f9995eee51a1b4f4a6bf9c
|
4
|
+
data.tar.gz: daa5ad0f99ff4a785fd664cba698cda7e79d540c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48346e91b649bd279a2966bb6dde84a6ee11bd251e181e8b96bb7cd628519aba8f58dfe8a3f9b370268a02c2302f16261ec1ce9d94da30976f1bed367f0817b2
|
7
|
+
data.tar.gz: 5710ab165795472d962d85f28b3bdbf148f1a17cf9146f6fef18a5da67c9b26e3191e830fd6a1ce5e3d9c2fbeeec2cd615a68773674ab898eb30d6472c8d81ca
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# aws-must - Minimum Viable Solution to Manage CloudFormation Templates - $Release:0.0.
|
1
|
+
# aws-must - Minimum Viable Solution to Manage CloudFormation Templates - $Release:0.0.13$
|
2
2
|
|
3
3
|
`aws-must` is a tool, which allows separating infrastructure
|
4
4
|
configuration and Amazon related syntax in CloudFormation JSON
|
@@ -103,26 +103,25 @@ template `./mustache/root.mustache` issue the command
|
|
103
103
|
|
104
104
|
aws-must.rb gen yaml_file
|
105
105
|
|
106
|
-
The
|
107
|
-
|
108
|
-
|
109
|
-
[aws-must-templates](https://github.com/jarjuk/aws-must-templates)
|
110
|
-
use the command
|
106
|
+
The location where to search Mustache templates can be set with `-m`
|
107
|
+
option.The option accepts list of directory paths (ending with `/`
|
108
|
+
character) or Gem names. For example, to override templates in Gem
|
109
|
+
[aws-must-templates](https://github.com/jarjuk/aws-must-templates)
|
110
|
+
with templates in directory `mydir` use the command
|
111
111
|
|
112
|
-
aws-must.rb gen yaml_file -
|
112
|
+
aws-must.rb gen yaml_file -m mydir/ aws-must-templates
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
A version constraint for the Gem can be specified followed by a comma
|
115
|
+
-character. For example, to use version specification `~>0.0.1`, issue
|
116
|
+
the command
|
117
117
|
|
118
|
-
aws-must.rb gen yaml_file -
|
118
|
+
aws-must.rb gen yaml_file -m 'aws-must-templates,~>0.0.1'
|
119
119
|
|
120
120
|
To extract documentation for the templates
|
121
121
|
|
122
122
|
aws-must.rb doc
|
123
123
|
|
124
|
-
The
|
125
|
-
the `gen` -command.
|
124
|
+
The `doc` -command supports also `-m` option.
|
126
125
|
|
127
126
|
Documentation is extracted from lines surrounded by **+++start+++**
|
128
127
|
and **+++close+++** tags, or by **+++fold-on+++** and
|
@@ -147,7 +146,6 @@ To dump YAML `yaml_file` in JSON format
|
|
147
146
|
|
148
147
|
Add the following lines to `Rakefile`
|
149
148
|
|
150
|
-
|
151
149
|
spec = Gem::Specification.find_by_name 'aws-must'
|
152
150
|
load "#{spec.gem_dir}/lib/tasks/demo.rake"
|
153
151
|
|
data/bin/aws-must.rb
CHANGED
@@ -53,12 +53,14 @@ class App < Thor
|
|
53
53
|
|
54
54
|
# ------------------------------------------------------------------
|
55
55
|
add_shared_option :template_gem, :aliases => "-g", :type => :string,
|
56
|
-
:desc => "Mustache template Gem name (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1')"
|
56
|
+
:desc => "Mustache template Gem name (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1') (DEPRECATED)"
|
57
57
|
|
58
58
|
add_shared_option :template_path, :aliases => "-t", :type =>
|
59
|
-
:string, :
|
60
|
-
:desc => "Directory holding mustache templates"
|
59
|
+
:string, :desc => "Directory holding mustache templates (DEPRECATED)"
|
61
60
|
|
61
|
+
add_shared_option :mustaches, :aliases => "-m", :type =>
|
62
|
+
:array, :default => [ "mustache/"],
|
63
|
+
:desc => "Array of directory paths (ending with slash '/' char e.g. 'mustache/') of Gem names (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1') holding mustache templates"
|
62
64
|
|
63
65
|
# ------------------------------------------------------------------
|
64
66
|
# action 'doc'
|
@@ -66,6 +68,7 @@ class App < Thor
|
|
66
68
|
desc "doc", "Extract template documentation"
|
67
69
|
|
68
70
|
shared_options :template_path
|
71
|
+
shared_options :mustaches
|
69
72
|
shared_options :template_gem
|
70
73
|
|
71
74
|
option :fold_on, :aliases => "-n", :type => :string,
|
@@ -108,7 +111,7 @@ LONGDESC
|
|
108
111
|
|
109
112
|
def doc( template_name=DEAFAULT_TEMPLATE )
|
110
113
|
|
111
|
-
@logger.info( "#{
|
114
|
+
@logger.info( "#{__method__} starting" )
|
112
115
|
|
113
116
|
|
114
117
|
my_options = option_adjust_common( options )
|
@@ -174,6 +177,7 @@ LONGDESC
|
|
174
177
|
desc "gen <yaml_file> [<template_name>]", "Generate CloudFormation JSON template"
|
175
178
|
|
176
179
|
shared_options :template_path
|
180
|
+
shared_options :mustaches
|
177
181
|
shared_options :template_gem
|
178
182
|
|
179
183
|
long_desc <<-LONGDESC
|
@@ -201,33 +205,90 @@ LONGDESC
|
|
201
205
|
|
202
206
|
def option_adjust_common( options )
|
203
207
|
|
204
|
-
raise "No optios
|
205
|
-
|
206
|
-
|
208
|
+
raise "No optios given" unless options
|
209
|
+
|
210
|
+
# options readonly - dup allows modification
|
211
|
+
options = options.dup
|
212
|
+
|
213
|
+
@logger.debug( "#{__method__}, options '#{options}'" )
|
214
|
+
|
215
|
+
options = option_template_gem_to_template_path( options ) if options[:template_gem]
|
216
|
+
options = option_template_path( options ) if options[:template_path]
|
217
|
+
|
218
|
+
warn <<-EOS unless options[:mustaches] && options[:mustaches].any?
|
219
|
+
|
220
|
+
Deprecation!!
|
221
|
+
|
222
|
+
Use option -m to define location of templates
|
223
|
+
|
224
|
+
Options -g and -t deprecated
|
225
|
+
EOS
|
226
|
+
|
227
|
+
options = option_mustaches_to_template_paths( options ) if options[:mustaches]
|
207
228
|
|
208
|
-
return
|
229
|
+
return options
|
209
230
|
end
|
210
231
|
|
232
|
+
# set `options[:template_path]` to an array of local directory
|
233
|
+
# paths parsed from list of options[:mustaches]
|
234
|
+
def option_mustaches_to_template_paths( options )
|
235
|
+
|
236
|
+
# init, NB: plural
|
237
|
+
options[:template_paths] = []
|
238
|
+
|
239
|
+
options[:mustaches].each do |mustache_def|
|
240
|
+
if mustache_def[-1] == '/' then
|
241
|
+
# directory with last char removed
|
242
|
+
options[:template_paths] << mustache_def[0..-1]
|
243
|
+
else
|
244
|
+
# gemname
|
245
|
+
options[:template_paths] << gem_name_to_template_path( mustache_def )
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
return options
|
250
|
+
end
|
211
251
|
|
252
|
+
# overrides -m option
|
253
|
+
def option_template_path( options )
|
254
|
+
# overrides -m option
|
255
|
+
options[:mustaches] = []
|
256
|
+
return options
|
257
|
+
end
|
258
|
+
|
259
|
+
# set 'options[:template_path]' to mustache directory withing
|
260
|
+
# `options[:template_gem]` Gem
|
212
261
|
def option_template_gem_to_template_path( options )
|
213
262
|
|
263
|
+
# overrides -m option
|
264
|
+
options[:mustaches] = []
|
265
|
+
|
266
|
+
options[:template_path] = gem_name_to_template_path( options[:template_gem] )
|
267
|
+
|
268
|
+
return options
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
# map 'gem_name_and_spec' to path of mustache templates
|
273
|
+
def gem_name_to_template_path( gem_name_and_spec )
|
274
|
+
|
214
275
|
# The version requirements are optional.
|
215
276
|
# You can also specify multiple version requirements, just append more at the end
|
216
|
-
gem_spec =
|
277
|
+
gem_spec = gem_name_and_spec.split(',')
|
217
278
|
gem_name, *gem_ver_reqs = gem_spec[0], gem_spec[1]
|
279
|
+
@logger.debug( "#{__method__}, gem_name=#{gem_name}, *gem_ver_reqs=#{gem_ver_reqs}" )
|
218
280
|
gdep = Gem::Dependency.new(gem_name, *gem_ver_reqs)
|
219
281
|
# find latest that satisifies
|
220
282
|
found_gspec = gdep.matching_specs.sort_by(&:version).last
|
283
|
+
@logger.debug( "#{__method__}, found_gspec=#{found_gspec}" )
|
221
284
|
# instead of using Gem::Dependency, you can also do:
|
222
285
|
# Gem::Specification.find_all_by_name(gem_name, *gem_ver_reqs)
|
223
286
|
|
224
287
|
if found_gspec
|
225
|
-
#
|
226
|
-
@logger.debug( "#{
|
227
|
-
|
228
|
-
|
229
|
-
options[:template_path] = "#{found_gspec.gem_dir}/mustache"
|
230
|
-
@logger.debug( "#{__FILE__}.#{__method__}, new-options=#{options}" )
|
288
|
+
@logger.debug( "#{__method__}, Requirement '#{gdep}' already satisfied by #{found_gspec.name}-#{found_gspec.version}" )
|
289
|
+
@logger.debug( "#{__method__}, old-options=#{options}" )
|
290
|
+
template_path = "#{found_gspec.gem_dir}/mustache"
|
291
|
+
@logger.debug( "#{__method__}, template_path=#{template_path}" )
|
231
292
|
else
|
232
293
|
#puts "Requirement '#{gdep}' not satisfied; installing..."
|
233
294
|
# ver_args = gdep.requirements_list.map{|s| ['-v', s] }.flatten
|
@@ -236,7 +297,7 @@ LONGDESC
|
|
236
297
|
raise "Could not find gem '#{gdep}' - try 'gem install #{gdep}'"
|
237
298
|
end
|
238
299
|
|
239
|
-
return
|
300
|
+
return template_path
|
240
301
|
|
241
302
|
end
|
242
303
|
|
data/lib/aws-must/template.rb
CHANGED
@@ -12,10 +12,6 @@ module AwsMust
|
|
12
12
|
# ------------------------------------------------------------------
|
13
13
|
# Attributes
|
14
14
|
|
15
|
-
# static
|
16
|
-
@@template_path = nil # directory where templates stored
|
17
|
-
@@template_extension = "mustache"# type part in filename
|
18
|
-
|
19
15
|
# instance
|
20
16
|
attr_writer :partials # f: partial-name --> template string
|
21
17
|
attr_writer :templates # f: template-name --> template string
|
@@ -25,10 +21,18 @@ module AwsMust
|
|
25
21
|
|
26
22
|
def initialize( options={} )
|
27
23
|
@logger = getLogger( PROGNAME, options )
|
28
|
-
@logger.info( "#{
|
29
|
-
@logger.debug( "#{
|
24
|
+
@logger.info( "#{__method__} created" )
|
25
|
+
@logger.debug( "#{__method__}, options='#{options}" )
|
26
|
+
|
27
|
+
@template_extension = "mustache"# type part in filename
|
28
|
+
|
30
29
|
# for mustache templates
|
31
|
-
|
30
|
+
if options[:template_paths] && options[:template_paths].any? then
|
31
|
+
@template_paths = options[:template_paths]
|
32
|
+
else
|
33
|
+
@template_paths = ( options[:template_path].respond_to?(:each) ? options[:template_path] : [ options[:template_path] ] )
|
34
|
+
end
|
35
|
+
|
32
36
|
end
|
33
37
|
|
34
38
|
# ------------------------------------------------------------------
|
@@ -51,56 +55,82 @@ module AwsMust
|
|
51
55
|
|
52
56
|
# method used by mustache framework - delegate to 'get_partial'
|
53
57
|
def partial(name)
|
54
|
-
@logger.debug( "#{
|
55
|
-
# File.read("#{template_path}/#{name}.#{template_extension}")
|
58
|
+
@logger.debug( "#{__method__} name=#{name}" )
|
56
59
|
get_partial( name )
|
57
60
|
end
|
58
61
|
|
59
62
|
# cache @partials - for easier extension
|
60
63
|
def get_partial( name )
|
61
|
-
@logger.debug( "#{
|
64
|
+
@logger.debug( "#{__method__} name=#{name}" )
|
62
65
|
return @partials[name] if @partials && @partials[name]
|
63
66
|
|
64
|
-
partial_file =
|
65
|
-
@logger.info( "#{
|
67
|
+
partial_file = get_template_filepath( name )
|
68
|
+
@logger.info( "#{__method__} read partial_file=#{partial_file}" )
|
66
69
|
File.read( partial_file )
|
67
70
|
end
|
68
71
|
|
69
72
|
# hide @templates - for easier extension
|
70
73
|
def get_template( name )
|
71
74
|
|
72
|
-
|
73
|
-
|
75
|
+
template_file = get_template_filepath( name )
|
76
|
+
@logger.info( "#{__method__} read template_file=#{template_file}" )
|
77
|
+
File.read( template_file )
|
74
78
|
|
75
|
-
|
76
|
-
|
79
|
+
end # def get_template( name )
|
80
|
+
|
81
|
+
|
82
|
+
# return path to an existing template file name
|
83
|
+
private
|
84
|
+
|
85
|
+
def get_template_filepath( name )
|
86
|
+
|
87
|
+
@template_paths.each do |directory|
|
88
|
+
|
89
|
+
template_path = get_template_filepath_in_directory( directory, name )
|
90
|
+
|
91
|
+
return template_path if File.exists?( template_path )
|
92
|
+
|
93
|
+
end # each
|
77
94
|
|
78
95
|
|
79
|
-
|
96
|
+
# could not find
|
97
|
+
|
98
|
+
raise <<-eos
|
99
|
+
|
100
|
+
No such template '#{name}' found in directories #{@template_paths.join(", ")}
|
80
101
|
|
81
|
-
Use opition -
|
102
|
+
Use opition -g list directories or Gems, where file '#{name}.#{@template_extension}' can be located.
|
82
103
|
|
83
104
|
eos
|
84
|
-
end
|
85
105
|
|
86
|
-
template_path = "#{@@template_path}/#{name}.#{@@template_extension}"
|
87
|
-
@logger.info( "#{__FILE__}.#{__method__} read template_path=#{template_path}" )
|
88
106
|
|
89
|
-
|
107
|
+
end
|
108
|
+
|
109
|
+
# return path to 'template_file' in an existing 'directory'
|
110
|
+
def get_template_filepath_in_directory( directory, template_file )
|
111
|
+
@logger.debug( "#{__method__} directory=#{directory}, template_file=#{template_file}" )
|
112
|
+
|
113
|
+
if ! File.exists?( directory ) then
|
90
114
|
raise <<-eos
|
91
115
|
|
92
|
-
No such
|
116
|
+
No such directory '#{directory}'.
|
93
117
|
|
94
|
-
|
95
|
-
|
118
|
+
Option -g should list
|
119
|
+
- existing paths OR
|
120
|
+
- Gems which includes 'mustache' directory
|
96
121
|
|
97
122
|
eos
|
123
|
+
|
98
124
|
end
|
99
125
|
|
126
|
+
template_path = "#{directory}/#{template_file}.#{@template_extension}"
|
127
|
+
@logger.info( "#{__method__} read template_path=#{template_path}" )
|
128
|
+
|
129
|
+
return template_path
|
100
130
|
|
101
|
-
File.read( template_path )
|
102
131
|
end
|
103
132
|
|
133
|
+
|
104
134
|
end # class
|
105
135
|
|
106
136
|
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-must
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jarjuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mustache
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.18
|
33
|
+
version: '0.18'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.18
|
40
|
+
version: '0.18'
|
41
41
|
description: |
|
42
42
|
aws-must is a tool, which allows separating infrastructure
|
43
43
|
configuration and Amazon related syntax using YAML and Mustache templates
|