class Gerrit::Command::Base

Abstract base class of all commands.

@abstract

Attributes

arguments[R]

@return [Array<String>]

config[R]

@return [Gerrit::Configuration]

ui[R]

@return [Gerrit::UI]

Public Class Methods

from_arguments(config, ui, arguments) click to toggle source

Create a command from a list of arguments.

@param config [Gerrit::Configuration] @param ui [Gerrit::UI] @param arguments [Array<String>] @return [Gerrit::Command::Base] appropriate command for the given

arguments
# File lib/gerrit/command/base.rb, line 17
def self.from_arguments(config, ui, arguments)
  cmd = arguments.first

  begin
    require "gerrit/command/#{Gerrit::Utils.snake_case(cmd)}"
  rescue LoadError => ex
    raise Gerrit::Errors::CommandInvalidError,
          "`gerrit #{cmd}` is not a valid command"
  end

  Gerrit::Command.const_get(Gerrit::Utils.camel_case(cmd)).new(config, ui, arguments)
end
new(config, ui, arguments) click to toggle source

@param config [Gerrit::Configuration] @param ui [Gerrit::UI] @param arguments [Array<String>]

# File lib/gerrit/command/base.rb, line 33
def initialize(config, ui, arguments)
  @config = config
  @ui = ui
  @arguments = arguments
end

Public Instance Methods

execute() click to toggle source

Executes the command given the previously-parsed arguments.

# File lib/gerrit/command/base.rb, line 47
def execute
  raise NotImplementedError, 'Define `execute` in Command subclass'
end
execute_command(command_arguments) click to toggle source

Executes another command from the same context as this command.

@param command_arguments [Array<String>]

# File lib/gerrit/command/base.rb, line 54
def execute_command(command_arguments)
  self.class.from_arguments(config, ui, command_arguments).execute
end
run() click to toggle source

Parses arguments and executes the command.

# File lib/gerrit/command/base.rb, line 40
def run
  # TODO: include a parse step here and remove duplicate parsing code from
  # individual commands
  execute
end

Private Instance Methods

client() click to toggle source

Returns a client for making requests to the Gerrit server.

@return [Gerrit::Client]

# File lib/gerrit/command/base.rb, line 72
def client
  @client ||= Gerrit::Client.new(@config)
end
repo() click to toggle source

Returns information about this repository.

@return [Gerrit::Repo]

# File lib/gerrit/command/base.rb, line 79
def repo
  @repo ||= Gerrit::Repo.new(@config)
end
spawn(args) click to toggle source

Execute a process and return the result including status and output.

@param args [Array<String>] @return [#status, stdout, stderr]

# File lib/gerrit/command/base.rb, line 87
def spawn(args)
  Gerrit::Subprocess.spawn(args)
end