Module: Thunder::ClassMethods
- Defined in:
- lib/thunder.rb
Overview
This module provides methods for any class that includes Thunder
Instance Method Summary collapse
-
#default_command(command) ⇒ Object
Set the default command to be executed when no suitable command is found.
-
#desc(usage, description = "") ⇒ Object
Describe the next method (or subcommand).
- #get_help_formatter ⇒ Object
-
#help_formatter(formatter) ⇒ Object
Set the help formatter.
-
#longdesc(description) ⇒ Object
Provide a long description for the next method (or subcommand).
-
#method_added(method) ⇒ Object
private
Registers a method as a thunder task.
-
#option(name, options = {}) ⇒ Object
Define an option for the next method (or subcommand).
-
#options_processor(processor) ⇒ Object
Set the options processor.
-
#subcommand(command, handler) ⇒ Object
Define a subcommand.
-
#thunder ⇒ Object
private
Get the thunder configuration.
Instance Method Details
#default_command(command) ⇒ Object
Set the default command to be executed when no suitable command is found.
175 176 177 |
# File 'lib/thunder.rb', line 175 def default_command(command) thunder[:default_command] = command end |
#desc(usage, description = "") ⇒ Object
Describe the next method (or subcommand). A longer description can be given using the #longdesc command
184 185 186 |
# File 'lib/thunder.rb', line 184 def desc(usage, description="") thunder[:usage], thunder[:description] = usage, description end |
#get_help_formatter ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/thunder.rb', line 142 def get_help_formatter unless thunder[:help_formatter] require File.("../thunder/help/default", __FILE__) thunder[:help_formatter] = Thunder::DefaultHelp end thunder[:help_formatter] end |
#help_formatter(formatter) ⇒ Object
Set the help formatter.
168 169 170 |
# File 'lib/thunder.rb', line 168 def help_formatter(formatter) thunder[:help_formatter] = formatter end |
#longdesc(description) ⇒ Object
Provide a long description for the next method (or subcommand).
191 192 193 |
# File 'lib/thunder.rb', line 191 def longdesc(description) thunder[:long_description] = description end |
#method_added(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Registers a method as a thunder task
152 153 154 155 156 |
# File 'lib/thunder.rb', line 152 def method_added(method) add_command(method.to_sym) do |command| command[:params] = instance_method(method).parameters end end |
#option(name, options = {}) ⇒ Object
Define an option for the next method (or subcommand)
208 209 210 211 212 213 214 215 216 |
# File 'lib/thunder.rb', line 208 def option(name, ={}) name = name.to_sym [:name] = name [:short] ||= name[0] [:type] ||= Boolean [:desc] ||= "" thunder[:options] ||= {} thunder[:options][name] = end |
#options_processor(processor) ⇒ Object
Set the options processor.
161 162 163 |
# File 'lib/thunder.rb', line 161 def (processor) thunder[:options_processor] = processor end |
#subcommand(command, handler) ⇒ Object
Define a subcommand
222 223 224 225 226 |
# File 'lib/thunder.rb', line 222 def subcommand(command, handler) add_command(command.to_sym) do |subcommand| subcommand[:subcommand] = handler end end |
#thunder ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the thunder configuration
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/thunder.rb', line 126 def thunder @thunder ||= { default_command: :help, commands: { help: { name: :help, usage: "help [COMMAND]", description: "list available commands or describe a specific command", long_description: nil, options: nil, default_help: true }, } } end |