module Thor::Base::ClassMethods

Public Instance Methods

class_at_least_one(*args, &block) click to toggle source

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
class_at_least_one_option_names() click to toggle source

Returns this class at least one of required options array set, looking up in the ancestors chain.

Rturns

Array[Array]

# File lib/thor/rich_options/base.rb, line 97
def class_at_least_one_option_names
  @class_at_least_one_option_names ||= from_superclass(:class_at_least_one_option_names, [])
end
class_exclusive(*args, &block) click to toggle source

Adds and declareds option group for exclusive options in the block and arguments. You can declare options as the outside of the block.

Parameters

Array

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
class_exclusive_option_names() click to toggle source

Returns this class exclusive options array set, looking up in the ancestors chain.

Rturns

Array[Array]

# File lib/thor/rich_options/base.rb, line 88
def class_exclusive_option_names
  @class_exclusive_option_names ||= from_superclass(:class_exclusive_option_names, [])
end

Protected Instance Methods

built_option_names(target, opt = {}, &block) click to toggle source

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_options_relation_for( target, relation, *args, &block) click to toggle source

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