Skip to content

Commit

Permalink
Add an example for #stop_on_unknown_option!
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Nov 3, 2012
1 parent c7f1136 commit 41dd1ed
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,35 @@ def check_unknown_options?(config) #:nodoc:
# options, and where those additional options should not be handled by
# Thor.
#
# ==== Example
#
# To better understand how this is useful, let's consider a task that calls
# an external command. A user may want to pass arbitrary options and
# arguments to that command. The task itself also accepts some options,
# which should be handled by Thor.
#
# class_option "verbose", :type => :boolean
# stop_on_unknown_option! :exec
# check_unknown_options! :except => :exec
#
# desc "exec", "Run a shell command"
# def exec(*args)
# puts "diagnostic output" if options[: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 tasks that should be affected.
def stop_on_unknown_option!(*task_names)
Expand Down

0 comments on commit 41dd1ed

Please sign in to comment.