Module: Redmine::Command::InstanceMethods

Defined in:
lib/redmine/command.rb

Overview

Special instance methods for Command objects that define a common interface:

  • #options can hold options parsed from command-line switches

  • #call can be invoked to run the command.

Instance Method Summary collapse

Instance Method Details

#call(arguments) ⇒ Object

Override #call to provide your custom logic for a command object. The #call in this module will be prepended to #call in your own objects, ensuring that when invoked, all options will first be parsed. All non-recognized options will be passed as-is to the original #call method.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/redmine/command.rb', line 67

def call(arguments)
  OptionParser.new do |o|
    o.banner = 'Usage: ' + self.class.usage_description
    o.separator ''
    instance_exec o, &self.class.usage_options
    o.on_tail '-h', '--help', 'Show this message' do
      puts o
      exit
    end
  end.parse!(arguments)
  super(arguments)
end

#optionsObject

An generic options hash that can be used to store preferences in from command line options, available in both the #usage block and the #call method.



58
59
60
# File 'lib/redmine/command.rb', line 58

def options
  @otions ||= {}
end