class Gerrit::Command::Base
Abstract base class of all commands.
@abstract
Attributes
@return [Array<String>]
@return [Gerrit::Configuration]
@return [Gerrit::UI]
Public Class Methods
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
@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
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
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
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
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
Returns information about this repository.
@return [Gerrit::Repo]
# File lib/gerrit/command/base.rb, line 79 def repo @repo ||= Gerrit::Repo.new(@config) end
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