Module: Quickl::Command::Options::InstanceMethods
- Defined in:
- lib/quickl/command/options.rb
Overview
module ClassMethods
Instance Method Summary collapse
-
#options ⇒ Object
Returns OptionParser instance.
-
#parse_options(argv, sep_support = :none) ⇒ Object
Parses options in ‘argv` with an OptionParser instance and returns non-options arguments.
Instance Method Details
#options ⇒ Object
Returns OptionParser instance
42 43 44 |
# File 'lib/quickl/command/options.rb', line 42 def @options ||= self.class.(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`
%w{--verbose hello -- quickl --say and world}
# => ["hello", "quickl", "--say", "and", "world"]
%w{--verbose hello -- quickl --say and world}, :keep
# => ["hello", "--", "quickl", "--say", "and", "world"]
%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 (argv, sep_support = :none) case sep_support when NilClass, :none .parse!(argv) when :split, :keep parts = Quickl.split_commandline_args(argv) parts[0] = .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., ex.backtrace end |