Class: Toys::StandardMiddleware::SetDefaultDescriptions
- Inherits:
-
Object
- Object
- Toys::StandardMiddleware::SetDefaultDescriptions
- Includes:
- Middleware
- Defined in:
- lib/toys/standard_middleware/set_default_descriptions.rb
Overview
This middleware sets default description fields for tools and command line arguments and flags that do not have them set otherwise.
You can modify the static descriptions for tools, namespaces, and the root tool by passing parameters to this middleware. For finer control, you can override methods to modify the description generation logic.
Constant Summary collapse
- DEFAULT_TOOL_DESC =
The default description for tools.
"(No tool description available)"
- DEFAULT_NAMESPACE_DESC =
The default description for namespaces.
"(A namespace of tools)"
- DEFAULT_ROOT_DESC =
The default description for the root tool.
"Command line tool built using the toys-core gem."
- DEFAULT_ROOT_LONG_DESC =
The default long description for the root tool.
[ "This command line tool was built using the toys-core gem. See" \ " https://www.rubydoc.info/gems/toys-core for more info.", "To replace this message, configure the SetDefaultDescriptions middleware." ].freeze
- ACCEPTABLE_NAMES =
A mapping of names for acceptable types
{ nil => "string", ::String => "nonempty string", ::TrueClass => "boolean", ::FalseClass => "boolean", ::OptionParser::DecimalInteger => "decimal integer", ::OptionParser::OctalInteger => "octal integer", ::OptionParser::DecimalNumeric => "decimal numeric" }.freeze
Instance Method Summary collapse
-
#config(tool, loader) ⇒ Object
Add default description text to tools.
-
#initialize(default_tool_desc: DEFAULT_TOOL_DESC, default_tool_long_desc: nil, default_namespace_desc: DEFAULT_NAMESPACE_DESC, default_namespace_long_desc: nil, default_root_desc: DEFAULT_ROOT_DESC, default_root_long_desc: DEFAULT_ROOT_LONG_DESC) ⇒ SetDefaultDescriptions
constructor
Create a SetDefaultDescriptions middleware given default descriptions.
Methods included from Middleware
Constructor Details
#initialize(default_tool_desc: DEFAULT_TOOL_DESC, default_tool_long_desc: nil, default_namespace_desc: DEFAULT_NAMESPACE_DESC, default_namespace_long_desc: nil, default_root_desc: DEFAULT_ROOT_DESC, default_root_long_desc: DEFAULT_ROOT_LONG_DESC) ⇒ SetDefaultDescriptions
Create a SetDefaultDescriptions middleware given default descriptions.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/toys/standard_middleware/set_default_descriptions.rb', line 108 def initialize(default_tool_desc: DEFAULT_TOOL_DESC, default_tool_long_desc: nil, default_namespace_desc: DEFAULT_NAMESPACE_DESC, default_namespace_long_desc: nil, default_root_desc: DEFAULT_ROOT_DESC, default_root_long_desc: DEFAULT_ROOT_LONG_DESC) @default_tool_desc = default_tool_desc @default_tool_long_desc = default_tool_long_desc @default_namespace_desc = default_namespace_desc @default_namespace_long_desc = default_namespace_long_desc @default_root_desc = default_root_desc @default_root_long_desc = default_root_long_desc end |
Instance Method Details
#config(tool, loader) ⇒ Object
Add default description text to tools.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/toys/standard_middleware/set_default_descriptions.rb', line 125 def config(tool, loader) data = {tool: tool, loader: loader} tool.flag_definitions.each do |flag| config_desc(flag, generate_flag_desc(flag, data), generate_flag_long_desc(flag, data)) end tool.arg_definitions.each do |arg| config_desc(arg, generate_arg_desc(arg, data), generate_arg_long_desc(arg, data)) end config_desc(tool, generate_tool_desc(tool, data), generate_tool_long_desc(tool, data)) yield end |