aws-must 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -14
  3. data/bin/aws-must.rb +77 -16
  4. data/lib/aws-must/template.rb +56 -26
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e420dcf4c1ad2882e09cf1b188333d3c84474df7
4
- data.tar.gz: 2e7da5a2e698cb5d2a28bdced3b0d2a8d12bb618
3
+ metadata.gz: 4df0abe6aafa2e3145f9995eee51a1b4f4a6bf9c
4
+ data.tar.gz: daa5ad0f99ff4a785fd664cba698cda7e79d540c
5
5
  SHA512:
6
- metadata.gz: f898429506e61f6229983f1eccb9a4352550dec71588e73154ef6e52970fe35d47dff655f1198c3f238105202b79e7336699f30675953dd1f6b49c26236ed16d
7
- data.tar.gz: 35dccbaff7ec723c1494de0891a4b788e90d5f7dde03f971a3d57d805c205e214224ce5acd5ba66403a4c639a34e584c0d88af438dad9cbe56c0cec3fb3750c4
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.12$
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 path of Mustache templates can be changed using `-t` option, or by
107
- giving the name of a gem with a `-g` option. For example, to use the
108
- latest version of
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 -g aws-must-templates
112
+ aws-must.rb gen yaml_file -m mydir/ aws-must-templates
113
113
 
114
- The version constraint for the gem can be specified followed by a
115
- comma -character. For example, to use version specification `~>0.0.1`,
116
- issue the command
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 -g 'aws-must-templates,~>0.0.1'
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 documentation command supports the same `-t` and `-g` options, as
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, :default => "mustache",
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( "#{__FILE__}.#{__method__} starting" )
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 give" unless options
205
- ret = options
206
- ret = option_template_gem_to_template_path( options ) if options[:template_gem]
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 ret
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 = options[:template_gem].split(',')
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
- # unfreeze options
226
- @logger.debug( "#{__FILE__}.#{__method__}, Requirement '#{gdep}' already satisfied by #{found_gspec.name}-#{found_gspec.version}" )
227
- @logger.debug( "#{__FILE__}.#{__method__}, old-options=#{options}" )
228
- options = options.dup
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 options
300
+ return template_path
240
301
 
241
302
  end
242
303
 
@@ -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( "#{__FILE__}.#{__method__} created" )
29
- @logger.debug( "#{__FILE__}.#{__method__}, options='#{options}" )
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
- @@template_path = options[:template_path] if options[:template_path]
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( "#{__FILE__}.#{__method__} name=#{name}" )
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( "#{__FILE__}.#{__method__} name=#{name}" )
64
+ @logger.debug( "#{__method__} name=#{name}" )
62
65
  return @partials[name] if @partials && @partials[name]
63
66
 
64
- partial_file = "#{@@template_path}/#{name}.#{template_extension}"
65
- @logger.info( "#{__FILE__}.#{__method__} read partial_file=#{partial_file}" )
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
- @logger.debug( "#{__FILE__}.#{__method__} name=#{name}" )
73
- return @templates[name] if @templates && @templates[name]
75
+ template_file = get_template_filepath( name )
76
+ @logger.info( "#{__method__} read template_file=#{template_file}" )
77
+ File.read( template_file )
74
78
 
75
- if ! File.exists?( @@template_path ) then
76
- raise <<-eos
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
- No such directory '#{@@template_path}'.
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 -t to point to an existing directory.
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
- if ! File.exists?( template_path ) then
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 file '#{template_path}'.
116
+ No such directory '#{directory}'.
93
117
 
94
- Use opition -t to point to a directory, which contains file '#{name}.#{@@template_extension}'
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.12
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-21 00:00:00.000000000 Z
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.1
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.1
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.1
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.1
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