Class: Aws::Cfn::Compiler::Main
- Defined in:
- lib/aws/cfn/compiler/main.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#initialize, #load_spec, #save_template, #validate
Constructor Details
This class inherits a constructor from Aws::Cfn::Compiler::Base
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aws/cfn/compiler/main.rb', line 12 def run @opts = Slop.parse(help: true) do # command File.basename(__FILE__,'.rb') on :d, :directory=, 'The directory containing template sections', as: String on :o, :output=, 'The JSON file to output', as: String on :s, :specification=, 'The specification to use when selecting components. A JSON or YAML file or JSON object', as: String on :f, :formatversion=, 'The AWS Template format version. ', { as: String, optional_argument: true, default: '2010-09-09' } on :p, :precedence=, 'The precedence of template component types. Default: rb,ruby,yaml,yml,json,js', { as: String, default: 'rb,ruby,yaml,yml,json,js' } on :t, :description=, "The AWS Template description. Default: output basename or #{File.basename(__FILE__,'.rb')}", { as: String, default: File.basename(__FILE__,'.rb') } on :x, :expandedpaths, 'Show expanded paths in output', { as: String, optional_argument: true, default: 'off', match: %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i } on :O, :overwrite, 'Overwrite existing generated source files. (HINT: Think twice ...)', { as: String, optional_argument: true, default: 'off', match: %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i } end unless @opts[:directory] puts @opts exit end @config[:precedence] = @opts[:precedence].split(%r',+\s*').reverse @config[:expandedpaths] = @opts[:expandedpaths].downcase.match %r'^(1|true|on|yes|enable|set)$' @config[:directory] = @opts[:directory] load_spec @opts[:specification] desc = @opts[:output] ? File.basename(@opts[:output]).gsub(%r/\.(json|yaml)/, '') : File.basename(__FILE__,'.rb') if @spec and @spec['Description'] desc = @spec['Description'] end vers = '2010-09-09' if @spec and @spec['AWSTemplateFormatVersion'] vers = @spec['AWSTemplateFormatVersion'] end # noinspection RubyStringKeysInHashInspection compiled = { 'AWSTemplateFormatVersion' => (@opts[:formatversion].nil? ? vers : @opts[:formatversion]), 'Description' => (@opts[:description].nil? ? desc : @opts[:description]), 'Mappings' => @items['Mappings'], 'Parameters' => @items['Parameters'], 'Resources' => @items['Resources'], 'Outputs' => @items['Outputs'], } validate(compiled) output_file = @opts[:output] || 'compiled.json' save_template(output_file,compiled) @logger.step '*** Compiled Successfully ***' end |