module Toys::FlagGroup
A FlagGroup
is a group of flags with the same requirement settings.
Public Class Methods
create(type: nil, name: nil, desc: nil, long_desc: nil)
click to toggle source
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
@param type [Symbol] The type of group. Default is `:optional`. @param desc [String,Array<String>,Toys::WrappableString] Short
description for the group. See {Toys::ToolDefinition#desc} for a description of allowed formats. Defaults to `"Flags"`.
@param long_desc [Array<String,Array<String>,Toys::WrappableString>]
Long description for the flag group. See {Toys::ToolDefinition#long_desc} for a description of allowed formats. Defaults to the empty array.
@param name [String,Symbol,nil] The name of the group, or nil for no
name.
@return [Toys::FlagGroup::Base] A flag group of the correct subclass.
# 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