class Gerrit::CLI

Command line application interface.

Public Class Methods

new(input:, output:) click to toggle source

Create a CLI that outputs to the given output destination.

@param input [Gerrit::Input] @param output [Gerrit::Output]

# File lib/gerrit/cli.rb, line 21
def initialize(input:, output:)
  @ui = UI.new(input, output)
end

Public Instance Methods

run(arguments) click to toggle source

Parses the given command-line arguments and executes appropriate logic based on those arguments.

@param [Array<String>] arguments @return [Integer] exit status code

# File lib/gerrit/cli.rb, line 30
def run(arguments)
  config = Configuration.load_applicable
  run_command(config, arguments)

  ExitCodes::OK
rescue => ex
  ErrorHandler.new(@ui).handle(ex)
end

Private Instance Methods

convert_arguments(arguments) click to toggle source
# File lib/gerrit/cli.rb, line 54
def convert_arguments(arguments)
  # Display all open changes by default
  return ['list'] if arguments.empty?

  return ['help'] if %w[-h --help].include?(arguments.first)
  return ['version'] if %w[-v --version].include?(arguments.first)

  arguments
end
run_command(config, arguments) click to toggle source

Executes the appropriate command given the list of command line arguments.

@param config [Gerrit::Configuration] @param ui [Gerrit::UI] @param arguments [Array<String>] @raise [Gerrit::Errors::GerritError] when any exceptional circumstance occurs

# File lib/gerrit/cli.rb, line 47
def run_command(config, arguments)
  arguments = convert_arguments(arguments)

  require 'gerrit/command/base'
  Command::Base.from_arguments(config, @ui, arguments).run
end