Class: Pawnee::Options

Inherits:
Thor::Options
  • Object
show all
Defined in:
lib/pawnee/pawnee/parser/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash_options = {}, defaults = {}) ⇒ Options

Add the config options in as defaults first



5
6
7
8
9
10
11
12
13
14
# File 'lib/pawnee/pawnee/parser/options.rb', line 5

def initialize(hash_options={}, defaults={})
  # TODO: Add options to flatten from yaml
  Pawnee::Base.config_options.each_pair do |key,value|
    unless defaults[key]
      defaults[key] = value
    end
  end
  
  super(hash_options, defaults)
end

Instance Method Details

#parse(args) ⇒ Object

Change the option parsing so it does not freeze the hash



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
# File 'lib/pawnee/pawnee/parser/options.rb', line 17

def parse(args)
  @pile = args.dup

  while peek
    match, is_switch = current_is_switch?
    shifted = shift

    if is_switch
      case shifted
        when SHORT_SQ_RE
          unshift($1.split('').map { |f| "-#{f}" })
          next
        when EQ_RE, SHORT_NUM
          unshift($2)
          switch = $1
        when LONG_RE, SHORT_RE
          switch = $1
      end

      switch = normalize_switch(switch)
      option = switch_option(switch)
      @assigns[option.human_name] = parse_peek(switch, option)
    elsif match
      @extra << shifted
      @extra << shift while peek && peek !~ /^-/
    else
      @extra << shifted
    end
  end

  check_requirement!

  assigns = Thor::CoreExt::HashWithIndifferentAccess.new(@assigns)
  # assigns.freeze
  assigns
end