Module: Redmine::Command
- Included in:
- Redmine::Commands::Issue::Activity, Redmine::Commands::Issue::Show, Redmine::Commands::Issues, Redmine::Commands::LeadTimes, Redmine::Commands::Projects
- Defined in:
- lib/redmine/command.rb
Overview
The Command mixin helps define command objects used in the command line interface. Classes can mix in this behaviour to make it easier to take command line arguments, parse them and use the resulting options in the command execution.
Usage example:
class MyCommand
extend Command
usage 'greet [OPTIONS]' do |o|
o.on '-n', '--name', 'Provide the name to be used' do |name|
[:name] = name
end
end
def call(arguments)
puts "Hello, #{[:name]}!"
end
end
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
-
.extended(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#usage(description, &block) ⇒ Object
Define the command line options available to this command.
-
#usage_description ⇒ Object
Get the usage description set with #usage.
-
#usage_options ⇒ Object
Get the
OptionParserdefinition block set with #usage.
Class Method Details
.extended(base) ⇒ Object
:nodoc:
25 26 27 |
# File 'lib/redmine/command.rb', line 25 def self.extended(base) # :nodoc: base.send(:prepend, InstanceMethods) end |
Instance Method Details
#usage(description, &block) ⇒ Object
Define the command line options available to this command. This is a wrapper around Ruby’s own OptionParser. Options defined here will be parsed out of incoming arguments, and what remains will be passed to #call. Within this block, you have access to an options hash that is also available in the #call method.
34 35 36 37 |
# File 'lib/redmine/command.rb', line 34 def usage(description, &block) @usage_description = description @usage_options = block end |
#usage_description ⇒ Object
Get the usage description set with #usage.
40 41 42 |
# File 'lib/redmine/command.rb', line 40 def usage_description @usage_description ||= '' end |
#usage_options ⇒ Object
Get the OptionParser definition block set with #usage.
45 46 47 |
# File 'lib/redmine/command.rb', line 45 def @usage_options ||= ->(opts) {} end |