Module: RakeCommander::Options::ClassMethods
- Defined in:
- lib/rake-commander/options.rb
Instance Method Summary collapse
-
#banner(desc = :not_used) ⇒ Object
Overrides the auto-generated banner.
-
#clear_options! ⇒ Object
Clears all the options.
-
#option(*args, override: true, reopen: false, **kargs, &block) ⇒ Object
Defines a new option or opens for edition an existing one if
reopen: trueis used. -
#option?(sym) ⇒ Boolean
Whether an option has been declared.
-
#option_get(sym) ⇒ RakeCommander::Option, NilClass
Retrieves the option.
-
#option_remove(*keys) ⇒ Object
Removes options with short or name
keysfrom options. -
#option_reopen(*args, override: false, **kargs, &block) ⇒ Object
It re-opens an option for edition.
-
#options ⇒ Array<RakeCommander::Option>
List of configured options.
-
#options? ⇒ Boolean
Are there options defined?.
-
#options_use(opts, override: true) ⇒ Object
Allows to use a set of options.
-
#parse_options(argv = ARGV, method: :parse, &middleware) ⇒ Array<String>
It builds the
OptionParserinjecting themiddlewareblock and parsesargv.
Instance Method Details
#banner(desc = :not_used) ⇒ Object
Overrides the auto-generated banner
31 32 33 34 35 |
# File 'lib/rake-commander/options.rb', line 31 def (desc = :not_used) return = desc unless desc == :not_used return if return if respond_to?(:task_options_banner, true) end |
#clear_options! ⇒ Object
Clears all the options.
118 119 120 121 |
# File 'lib/rake-commander/options.rb', line 118 def = {} self end |
#option(*args, override: true, reopen: false, **kargs, &block) ⇒ Object
- If override is
true, it will with a Warning when sameshortornameclashes.
Defines a new option or opens for edition an existing one if reopen: true is used.
40 41 42 43 44 |
# File 'lib/rake-commander/options.rb', line 40 def option(*args, override: true, reopen: false, **kargs, &block) return option_reopen(*args, override: override, **kargs, &block) if reopen opt = option_class.new(*args, **kargs, &block) (opt, override: override) end |
#option?(sym) ⇒ Boolean
Returns whether an option has been declared.
108 109 110 |
# File 'lib/rake-commander/options.rb', line 108 def option?(sym) .key?(sym.to_sym) end |
#option_get(sym) ⇒ RakeCommander::Option, NilClass
Returns retrieves the option.
102 103 104 |
# File 'lib/rake-commander/options.rb', line 102 def option_get(sym) [sym.to_sym] end |
#option_remove(*keys) ⇒ Object
Removes options with short or name keys from options
61 62 63 64 65 66 67 |
# File 'lib/rake-commander/options.rb', line 61 def option_remove(*keys) keys.map do |key| aux = option_class.new(key, sample: true) opt = .values_at(aux.name, aux.short).compact.first (opt) if opt end end |
#option_reopen(*args, override: false, **kargs, &block) ⇒ Object
- If
overrideisfalse, it will fail to change thenameor theshort` when they are already taken by some other option. - It will have the effect of overriding existing options
when short and name are provided, name takes precedence over short
in the lookup (to identify the existing option)
It re-opens an option for edition. If it does not exist, it upserts it.
53 54 55 56 57 58 |
# File 'lib/rake-commander/options.rb', line 53 def option_reopen(*args, override: false, **kargs, &block) aux = option_class.new(*args, **kargs, sample: true, &block) opt = .values_at(aux.name, aux.short).compact.first return option(*args, **kargs, &block) unless opt (opt, opt.merge(aux), override: override) end |
#options ⇒ Array<RakeCommander::Option>
List of configured options
96 97 98 |
# File 'lib/rake-commander/options.rb', line 96 def .values.uniq end |
#options? ⇒ Boolean
Returns are there options defined?.
113 114 115 |
# File 'lib/rake-commander/options.rb', line 113 def !.empty? end |
#options_use(opts, override: true) ⇒ Object
it does a deep dup of each option.
Allows to use a set of options
74 75 76 77 78 79 80 |
# File 'lib/rake-commander/options.rb', line 74 def (opts, override: true) raise "Could not obtain list of RakeCommander::Option from #{opts.class}" unless opts = (opts) opts.each do |opt| (opt.deep_dup, override: override) end self end |
#parse_options(argv = ARGV, method: :parse, &middleware) ⇒ Array<String>
this method is extended in via the following modules:
RakeCommander::Options::Result: makes the method to return aHashwith results, as well as captures/moves the leftovers to their own keyed argument.RakeCommander::Options:Error: adds error handling (i.e. forward to rake commander errors)
It builds the OptionParser injecting the middleware block and parses argv
90 91 92 |
# File 'lib/rake-commander/options.rb', line 90 def (argv = ARGV, method: :parse, &middleware) (&middleware).send(method, argv) end |