class Redmine::Cli

Command line interface dispatcher: invoke subcommands based on incoming command line switches.

Public Class Methods

new(redmine_client:) click to toggle source
# File lib/redmine/cli.rb, line 8
def initialize(redmine_client:)
  @redmine = redmine_client
end

Public Instance Methods

call(arguments) click to toggle source
# File lib/redmine/cli.rb, line 12
def call(arguments)
  subcommand, *other_args = arguments
  if subcommand =~ /^\d+$/
    call_issue_command(subcommand, other_args)
  elsif subcommand =~ /^\w/
    call_subcommand(subcommand, other_args)
  else
    option_parser.parse(arguments)
  end
end

Private Instance Methods

call_issue_command(cmd, args) click to toggle source
# File lib/redmine/cli.rb, line 33
def call_issue_command(cmd, args)
  Commands::Issue.new(issue_id: cmd, redmine: @redmine).call(args)
end
call_subcommand(cmd, args) click to toggle source
# File lib/redmine/cli.rb, line 25
def call_subcommand(cmd, args)
  command_name_to_class(cmd).new(redmine: @redmine).call(args)
end
command_name_to_class(cmd) click to toggle source
# File lib/redmine/cli.rb, line 29
def command_name_to_class(cmd)
  Commands.const_get(cmd.split('_').map(&:capitalize).join)
end
option_parser() click to toggle source
# File lib/redmine/cli.rb, line 37
    def option_parser # rubocop:disable Metrics/MethodLength
      OptionParser.new do |o|
        o.banner = <<~EOS
        redmine [SUBCOMMAND] [OPTIONS]

        Perform common operations in a Redmine issue tracker from the command
        line.

        Available subcommands:

        projects
        issues
        show
        activity
        lead_times

        Generic options:
        EOS
        o.separator ''
        o.on_tail '-h', '--help', 'Show this message' do
          puts o
          exit
        end
        o.on_tail '-v', '--version', 'Display version number' do
          puts Redmine::VERSION
          exit
        end
      end
    end