Module: Aws::Cfn::Compiler::Options
- Included in:
- Base
- Defined in:
- lib/aws/cfn/compiler/mixins/options.rb
Instance Method Summary collapse
- #find_mia(list) ⇒ Object
- #hint_paths(p, pwd, n = 0, rel = '', f = nil) ⇒ Object
-
#parse_options ⇒ Object
TODO: [2014-06-29 Christo] Hook into super class and add on options instead of starting from scratch every time.
- #report_mia(path, mia, type) ⇒ Object
- #set_config_options ⇒ Object
- #set_config_path_option(value, envstr, default, listsym, type, relto = nil) ⇒ Object
Instance Method Details
#find_mia(list) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/aws/cfn/compiler/mixins/options.rb', line 108 def find_mia(list) mia = [] list.each do |path| unless File.directory? path mia << path end end mia end |
#hint_paths(p, pwd, n = 0, rel = '', f = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/aws/cfn/compiler/mixins/options.rb', line 118 def hint_paths(p,pwd,n=0,rel='',f=nil) hints = [] d = p until File.directory?(d) if d == '.' return hints end d = File.dirname(d) end unless f q = d Range.new(1,n).each do d = File.dirname(d) end f = File.basename(p) r = pwd.gsub(%r'^#{q}','').split(File::SEPARATOR) if r.size > 0 r = r[1..-1] end if r.size > 0 rel = r.map{|_| '..'}.join(File::SEPARATOR) end pwd = d end Dir.glob("#{d}/*").each do |path| if File.directory?(path) if path.match %r'/#{f}' hints << File.join(rel,path.gsub(%r'^#{File.dirname(d)}','')) else hints << hint_paths(path,pwd,n,rel,f) end end end hints.flatten end |
#parse_options ⇒ Object
TODO: [2014-06-29 Christo] Hook into super class and add on options instead of starting from scratch every time
7 8 9 10 11 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 |
# File 'lib/aws/cfn/compiler/mixins/options.rb', line 7 def @opts.on :b, :brick_path=, 'A list of paths to template components (bricks). May also set as the BRICK_PATH environment variable.', { as: String, default: 'bricks' } @opts.on :S, :stack_path=, 'A list of paths to stacks. May also set as the STACK_PATH environment variable.', { as: String, default: '.' } @opts.on :F, :format=, 'The output format of the components. [JSON|YAML|Ruby]', { as: String, match: @format_regex, default: 'yaml' } @opts.on :s, :specification=, 'The specification to use when selecting components. A JSON or YAML file', { as: String } @opts.on :f, :formatversion=, 'The AWS Template format version. ', {as: String, default: '2010-09-09' } @opts.on :D, :description=, 'The AWS Template description. Default: template name', { as: String } @opts.on :p, :parametersfile=, 'The parameters file for the template', { as: String } @opts.on :i, :stackinifile=, 'The INI file for the stack builder == build.py', { as: String } @opts.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', } @opts.parse! if ARGV.size > 0 puts @opts puts "Extra arguments! #{ARGV}" exit 1 end unless @opts[:specification] puts @opts abort! "Missing required option --specification" end end |
#report_mia(path, mia, type) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/aws/cfn/compiler/mixins/options.rb', line 96 def report_mia(path, mia, type) hints = [] mia.each do |p| hints << hint_paths(p, Dir.pwd) end hints.flatten! abort! "Invalid #{type}: #{path}! #{mia.size > 1 ? 'These' : 'This'} path#{mia.size > 1 ? 's' : ''} does not exist or cannot be read!\n #{mia.join("\n\t")} Did you mean one of these? #{@config[:expandedpaths] ? "(Above #{Dir.pwd})" : ""} \t#{hints.join("\n\t")}\n" end |
#set_config_options ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/aws/cfn/compiler/mixins/options.rb', line 38 def @config[:precedence] = @opts[:precedence].split(%r',+\s*').reverse @optional ||= {} @optional[:directory] = true setup_config set_config_path_option(@config[:stack_path],'STACK_PATH','.',:stack_path_list,'stack path') set_config_path_option(@config[:brick_path],'BRICK_PATH',@config[:directory],:brick_path_list,'brick path',:stack_path_list) end |
#set_config_path_option(value, envstr, default, listsym, type, relto = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aws/cfn/compiler/mixins/options.rb', line 51 def set_config_path_option(value,envstr,default,listsym,type,relto=nil) if value path = value elsif ENV[envstr] path = ENV[envstr] else path = default end if path @config[listsym] = parseList(path, ':') newlist = @config[listsym].map{ |r| if relto if r.match(%r'^/') # Absolute paths not relative to stacks r else a = [] @config[relto].each{|b| # noinspection RubyAssignmentExpressionInConditionalInspection if File.directory?(p=File.(File.join(b,r))) a << File.realpath(p) end } a end else File.(r) end } @config[listsym] = newlist.flatten.uniq mia = find_mia(@config[listsym]) if mia.size > 0 report_mia(path, mia, type) end @config[listsym].each { |p| if File.directory?((lib = File.join(p, 'lib'))) $:.unshift lib end } end end |