Method: Bundler::Thor.stop_on_unknown_option!
- Defined in:
- lib/bundler/vendor/thor/lib/thor.rb
.stop_on_unknown_option!(*command_names) ⇒ Object
Stop parsing of options as soon as an unknown option or a regular argument is encountered. All remaining arguments are passed to the command. This is useful if you have a command that can receive arbitrary additional options, and where those additional options should not be handled by Bundler::Thor.
Example
To better understand how this is useful, let’s consider a command that calls an external command. A user may want to pass arbitrary options and arguments to that command. The command itself also accepts some options, which should be handled by Bundler::Thor.
class_option "verbose", :type => :boolean
stop_on_unknown_option! :exec
:except => :exec
desc "exec", "Run a shell command"
def exec(*args)
puts "diagnostic output" if [:verbose]
Kernel.exec(*args)
end
Here exec
can be called with --verbose
to get diagnostic output, e.g.:
$ thor exec --verbose echo foo
diagnostic output
foo
But if --verbose
is given after echo
, it is passed to echo
instead:
$ thor exec echo --verbose foo
--verbose foo
Parameters
- Symbol …
-
A list of commands that should be affected.
325 326 327 |
# File 'lib/bundler/vendor/thor/lib/thor.rb', line 325 def stop_on_unknown_option!(*command_names) @stop_on_unknown_option = stop_on_unknown_option | command_names end |