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

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.



7
8
9
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 7

def config
  @config
end

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 6

def opts
  @opts
end

Class Method Details

.included(includer) ⇒ Object



119
120
121
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 119

def self.included(includer)

end

Instance Method Details

#parse_optionsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 61

def parse_options

  setup_options

  @opts.parse!

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

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

  setup_config

end

#setup_configObject



81
82
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
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 81

def setup_config

  [:overwrite, :functions, :force, :expandedpaths  ].each { |cfg|
    @config[cfg] = (not @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_opts] = lambda{|mlll| {
      :pattern      => "%#{mlll}l: %m %C\n",
      :date_pattern => '%Y-%m-%d %H:%M:%S',
      :color_scheme => 'compiler'
  }
  }
  @config[:log_level] ||= :info
  @logger = getLogger(@config)
end

#setup_optionsObject



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws/cfn/dsl/mixins/options.rb', line 9

def setup_options
  @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)$'

  @opts = Slop.new(help: true) 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}

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

end