module Thor::Base::ClassMethods
Public Instance Methods
Adds and declareds option group for required at least one of options in the block and arguments. You can declare options as the outside of the block.
Examples¶ ↑
class_at_least_one do class_option :one class_option :two end
Or
class_option :one class_option :two class_at_least_one :one, :two
If you do not give “–one” and “–two”. AtLeastOneRequiredArgumentError
will be raised. You can use class_at_least_one
and class_exclusive
at the same time.
class_exclusive do class_at_least_one do class_option :one class_option :two end end
Then it is required either only one of “–one” or “–two”.
# File lib/thor/rich_options/base.rb, line 158 def class_at_least_one(*args, &block) register_options_relation_for(:class_options, :class_at_least_one_option_names, *args, &block) end
Adds and declareds option group for exclusive options in the block and arguments. You can declare options as the outside of the block.
Parameters¶ ↑
Examples¶ ↑
class_exclusive do class_option :one class_option :two end
Or
class_option :one class_option :two class_exclusive :one, :two
If you give “–one” and “–two” at the same time. ExclusiveArgumentsError will be raised.
# File lib/thor/rich_options/base.rb, line 124 def class_exclusive(*args, &block) register_options_relation_for(:class_options, :class_exclusive_option_names, *args, &block) end
Protected Instance Methods
Get target(method_options or class_options) options of before and after by block evaluation.
# File lib/thor/rich_options/base.rb, line 178 def built_option_names(target, opt = {}, &block) before = command_scope_member(target, opt).map{ |k,v| v.name } instance_eval(&block) after = command_scope_member(target, opt).map{ |k,v| v.name } after - before end
Register a relation of options for target(method_option/class_option) by args and block.
# File lib/thor/rich_options/base.rb, line 168 def register_options_relation_for( target, relation, *args, &block) opt = args.pop if args.last.is_a? Hash opt ||= {} names = args.map{ |arg| arg.to_s } names += built_option_names(target, opt, &block) if block_given? command_scope_member(relation, opt) << names end