Module: Toys::FlagGroup

Defined in:
lib/toys/flag_group.rb

Overview

A FlagGroup is a group of flags with the same requirement settings.

Defined Under Namespace

Classes: AtLeastOne, AtMostOne, Base, ExactlyOne, Optional, Required

Class Method Summary collapse

Class Method Details

.create(type: nil, name: nil, desc: nil, long_desc: nil) ⇒ Toys::FlagGroup::Base

Create a flag group object of the given type.

The type should be one of the following symbols:

  • :optional All flags in the group are optional
  • :required All flags in the group are required
  • :exactly_one Exactly one flag in the group must be provided
  • :at_least_one At least one flag in the group must be provided
  • :at_most_one At most one flag in the group must be provided

Parameters:

  • type (Symbol) (defaults to: nil)

    The type of group. Default is :optional.

  • desc (String, Array<String>, Toys::WrappableString) (defaults to: nil)

    Short description for the group. See ToolDefinition#desc for a description of allowed formats. Defaults to "Flags".

  • long_desc (Array<String,Array<String>,Toys::WrappableString>) (defaults to: nil)

    Long description for the flag group. See ToolDefinition#long_desc for a description of allowed formats. Defaults to the empty array.

  • name (String, Symbol, nil) (defaults to: nil)

    The name of the group, or nil for no name.

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/toys/flag_group.rb', line 30

def self.create(type: nil, name: nil, desc: nil, long_desc: nil)
  type ||= Optional
  unless type.is_a?(::Class)
    class_name = ModuleLookup.to_module_name(type)
    type =
      begin
        FlagGroup.const_get(class_name)
      rescue ::NameError
        raise ToolDefinitionError, "Unknown flag group type: #{type}"
      end
  end
  unless type.ancestors.include?(Base)
    raise ToolDefinitionError, "Unknown flag group type: #{type}"
  end
  type.new(name, desc, long_desc)
end