Module: SimpleTemplater::ArgvParsingMixin

Defined in:
lib/simple-templater/argv_parsing.rb

Instance Method Summary collapse

Instance Method Details

#parse!Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/simple-templater/argv_parsing.rb', line 5

def parse!
  self.inject(Hash.new) do |options, argument|
    case argument
    when /^--no-([^=]+)$/ # --no-git-repository
      options[$1.gsub("-", "_").to_sym] = false
    when /^--([^=]+)$/    # --git-repository
      options[$1.gsub("-", "_").to_sym] = true
    when /^--([^=]+)=([^,]+)$/ # --controller=post
      key, value = $1, $2
      options[key.gsub("-", "_").to_sym] = value.dup
    when /^--([^=]+)=(.+)$/    # --controllers=posts,comments
      key, value = $1, $2
      options[key.gsub("-", "_").to_sym] = value.split(",")
    else
      raise "Parsing failed on: #{argument}"
    end
    options
  end
end