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
-
#option(*args, **kargs, &block) ⇒ Object
Defines a new option.
- #options ⇒ Object
- #options? ⇒ Boolean
- #options_hash ⇒ Object
-
#parse_options(argv = ARGV, leftovers: [], &middleware) ⇒ Hash
It builds the
OptionParserinjecting themiddlewareblock. -
#results_with_all_defaults(value = nil) ⇒ Boolean
Whether results should include options defined with a default, regarless if they are invoked.
-
#use_options(options) ⇒ Object
Allows to use a set of options.
Instance Method Details
#banner(desc = :not_used) ⇒ Object
Overrides the auto-generated banner
54 55 56 57 58 |
# File 'lib/rake-commander/options.rb', line 54 def (desc = :not_used) return = desc unless desc == :not_used return if return if respond_to?(:task_options_banner, true) end |
#clear_options! ⇒ Object
30 31 32 |
# File 'lib/rake-commander/options.rb', line 30 def = {} end |
#option(*args, **kargs, &block) ⇒ Object
Note:
- It will override with a Warning options with same
shortorname
Defines a new option
47 48 49 50 51 |
# File 'lib/rake-commander/options.rb', line 47 def option(*args, **kargs, &block) opt = RakeCommander::Option.new(*args, **kargs, &block) (opt) self end |
#options ⇒ Object
22 23 24 |
# File 'lib/rake-commander/options.rb', line 22 def .values.uniq end |
#options? ⇒ Boolean
26 27 28 |
# File 'lib/rake-commander/options.rb', line 26 def !.empty? end |
#options_hash ⇒ Object
18 19 20 |
# File 'lib/rake-commander/options.rb', line 18 def ||= {} end |
#parse_options(argv = ARGV, leftovers: [], &middleware) ⇒ Hash
It builds the OptionParser injecting the middleware block.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rake-commander/options.rb', line 72 def (argv = ARGV, leftovers: [], &middleware) (middleware) do || argv = pre_parse_arguments(argv, options: ) pp argv leftovers.push(*.parse(argv)) rescue OptionParser::MissingArgument => e raise RakeCommander::Options::MissingArgument, e, cause: nil rescue OptionParser::InvalidArgument => e error = RakeCommander::Options::InvalidArgument error = error.new(e) opt = [error.option_sym] msg = "missing required argument: #{opt&.name_hyphen} (#{opt&.short_hyphen})" raise RakeCommander::Options::MissingArgument, msg, cause: nil if opt&.argument_required? raise error, e, cause: nil end.tap do |results| check_required_presence!(results) end end |
#results_with_all_defaults(value = nil) ⇒ Boolean
Returns whether results should include options defined with a default, regarless if they are invoked.
62 63 64 65 66 67 68 |
# File 'lib/rake-commander/options.rb', line 62 def results_with_all_defaults(value = nil) if value.nil? @results_with_all_defaults || false else @results_with_all_defaults = !!value end end |
#use_options(options) ⇒ Object
Allows to use a set of options
36 37 38 39 40 41 42 |
# File 'lib/rake-commander/options.rb', line 36 def () = .values if .is_a?(Hash) .each do |opt| (opt) end self end |