Module: Cask::Cmd::Options

Included in:
Cask::Cmd, AbstractCommand
Defined in:
brew/Library/Homebrew/cask/cmd/options.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#process_arguments(*arguments) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'brew/Library/Homebrew/cask/cmd/options.rb', line 44

def process_arguments(*arguments)
  parser = OptionParser.new do |opts|
    next if self.class.options.nil?

    self.class.options.each do |option_name, option_method|
      option_type = case option_name.split(/(\ |\=)/).last
      when "PATH"
        Pathname
      when /\w+(,\w+)+/
        Array
      end

      opts.on(option_name, *option_type) do |value|
        if option_method.respond_to?(:call)
          option_method.call(value)
        else
          send(:"#{option_method}=", value)
        end
      end
    end
  end
  parser.parse(*arguments)
end