module Redmine::Command

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|
      options[:name] = name
    end
  end

  def call(arguments)
    puts "Hello, #{options[:name]}!"
  end
end

Public Instance Methods

usage(description, &block) click to toggle source

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.

# File lib/redmine/command.rb, line 34
def usage(description, &block)
  @usage_description = description
  @usage_options = block
end
usage_description() click to toggle source

Get the usage description set with usage.

# File lib/redmine/command.rb, line 40
def usage_description
  @usage_description ||= ''
end
usage_options() click to toggle source

Get the OptionParser definition block set with usage.

# File lib/redmine/command.rb, line 45
def usage_options
  @usage_options ||= ->(opts) {}
end