Module: Quickl::Command::Options::InstanceMethods

Defined in:
lib/quickl/command/options.rb

Overview

module ClassMethods

Instance Method Summary collapse

Instance Method Details

#optionsObject

Returns OptionParser instance



42
43
44
# File 'lib/quickl/command/options.rb', line 42

def options
  @options ||= self.class.build_options(self)
end

#parse_options(argv, sep_support = :none) ⇒ Object

Parses options in ‘argv` with an OptionParser instance and returns non-options arguments.

The following example illustrates the role of ‘sep_support`

parse_options %w{--verbose hello -- quickl --say and world}
# => ["hello", "quickl", "--say", "and", "world"]

parse_options %w{--verbose hello -- quickl --say and world}, :keep
# => ["hello", "--", "quickl", "--say", "and", "world"]

parse_options %w{--verbose hello -- quickl --say and world}, :split
# => [["hello"], ["quickl", "--say", and", "world"]]


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/quickl/command/options.rb', line 61

def parse_options(argv, sep_support = :none)
  case sep_support
  when NilClass, :none
    options.parse!(argv)
  when :split, :keep
    parts = Quickl.split_commandline_args(argv)
    parts[0] = options.parse!(parts[0])
    if sep_support == :keep
      parts.inject(nil){|memo,arr| memo ? memo + ["--"] + arr : arr.dup}
    else
      parts
    end
  end
rescue OptionParser::ParseError => ex
  raise Quickl::InvalidOption, ex.message, ex.backtrace
end