Module: Aws::Cfn::Dsl::Options

Includes:
DLDInternet::Mixlib::CLI::Parsers
Included in:
Base
Defined in:
lib/aws/cfn/dsl/mixins/options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 15

def config
  @config
end

#optsObject (readonly)

Returns the value of attribute opts.



14
15
16
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 14

def opts
  @opts
end

Class Method Details

.included(includer) ⇒ Object



136
137
138
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 136

def self.included(includer)

end

Instance Method Details

#parse_optionsObject



73
74
75
76
77
78
79
80
81
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 73

def parse_options

  setup_options

  @opts.parse!

  setup_config

end

#setup_configObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 83

def setup_config

  unless @opts[:directory] or @optional[:directory]
    puts @opts
    abort! "Missing required option. --directory is required"
  end

  unless @opts[:template]
    puts @opts
    abort! "Missing required option --template"
  end

  [:overwrite, :functions, :force, :expandedpaths, :debug, :trace  ].each { |cfg|
    @config[cfg] = (not (@opts[cfg].nil? or @opts[cfg].downcase.match(@on_yes_regex).nil?))
  }

  @opts.options.each{ |opt|
    key = opt.long.to_sym
    unless @config.has_key?(key)
      @config[key] = opt.value unless opt.value.nil?
    end
  }

  lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
      :trace => :blue,
      :debug => :cyan,
      :info  => :green,
      :step  => :green,
      :warn  => :yellow,
      :error => :red,
      :fatal => :red,
      :todo  => :purple,
  })
  scheme = lcs.scheme
  scheme['trace'] = "\e[38;5;33m"
  scheme['fatal'] = "\e[38;5;89m"
  scheme['todo']  = "\e[38;5;55m"
  lcs.scheme scheme
  @config[:log_level] ||= :info
  @config[:log_opts] = lambda{|mlll| {
      :pattern      => "%#{mlll}l: %m %g\n",
      :date_pattern => '%Y-%m-%d %H:%M:%S',
      :color_scheme => 'compiler',
      :trace        => (@config[:trace].nil? ? false : @config[:trace]),
      # [2014-06-30 Christo] DO NOT do this ... it needs to be a FixNum!!!!
      # If you want to do ::Logging.init first then fine ... go ahead :)
      # :level        => @config[:log_level],
  }
  }
  @logger = getLogger(@config)

end

#setup_options(opts = @opts) ⇒ Object



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/dsl/mixins/options.rb', line 20

def setup_options(opts=@opts)
  @on_off_regex = %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i
  @format_regex = %r/ruby|rb|yaml|yml|json|js/i
  @on_yes_regex = %r'^(1|true|on|yes|enable|set)$'
  @optional   ||= {}
  unless opts
    @opts ||= Slop.new(help: true)
    opts = @opts
  end

  with opts do
    on :t, :template=,      'The template', as: String
    on :d, :directory=,     'The directory with template components.', as: String

    on :l, :log_level=, "Logging level. [#{::Logging::LEVELS.keys.join('|')}]", {as: String,
                                                                                   default: 'step',
                                                                                   match: %r/#{::Logging::LEVELS.keys.join('|')}/i}

    [
        { short: :n, long: :functions=,    default: 'off', on: 'on',      desc: 'Enable function use'},
        { short: :x, long: :expandedpaths, default: 'off', on:      'on', desc: 'Show expanded paths in output',                                       },
        { short: :O, long: :overwrite,     default: 'off', on:      'on', desc: 'Overwrite existing generated source files. (HINT: Think twice ...)',  },
    ].each do |opt|
      on opt[:short], opt[:long], opt[:desc], {as: String,
                                     optional_argument: true,
                                     default: opt[:default],
                                     match: @on_off_regex } do |_|
        me = @options.select { |o|
          o.long == opt[:long].to_s
        }[0]
        me.config[:default] = opt[:on]
      end
    end
    [
        { short: :overwrite,  default: 'off', on:      'on', desc: 'Overwrite existing generated source files. (HINT: Think twice ...)',  },
        { short: :force,      default: 'off', on:      'on', desc: 'Continue processing and ignore warnings',                             },
        { short: :debug,      default: 'off', on:      'on', desc: 'Turn on debugging',                                                   },
        { short: :trace,      default: 'off', on:      'on', desc: 'Turn on tracing',                                                     },
    ].each do |opt|
      on opt[:short], opt[:desc], {as: String,
                                     optional_argument: true,
                                     default: opt[:default],
                                     match: @on_off_regex } do |_|
        me = @options.select { |o|
          o.long == opt[:short].to_s
        }[0]
        me.config[:default] = opt[:on]
      end
    end
  end

end