Module: Hbc::CLI::Options

Included in:
Hbc::CLI, AbstractCommand
Defined in:
Library/Homebrew/cask/lib/hbc/cli/options.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
# File 'Library/Homebrew/cask/lib/hbc/cli/options.rb', line 4

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#process_arguments(*arguments) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'Library/Homebrew/cask/lib/hbc/cli/options.rb', line 39

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