Class: Homebrew::AbstractCommand Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers
Defined in:
abstract_command.rb

Overview

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Subclass this to implement a brew command. This is preferred to declaring a named function in the Homebrew module, because: - Each Command lives in an isolated namespace. - Each Command implements a defined interface. - args is available as an ivar, and thus does not need to be passed as an argument to helper methods. - Subclasses no longer need to reference CLI::Parser or parse args explicitly.

To subclass, implement a run method and provide a cmd_args block to document the command and its allowed args. To generate method signatures for command args, run brew typecheck --update.

Direct Known Subclasses

Cmd::Analytics, Cmd::Autoremove, Cmd::Cache, Cmd::Caskroom, Cmd::Cellar, Cmd::CleanupCmd, Cmd::CommandsCmd, Cmd::CompletionsCmd, Cmd::Config, Cmd::Deps, Cmd::Desc, Cmd::Developer, Cmd::Docs, Cmd::Doctor, Cmd::Env, Cmd::FetchCmd, Cmd::GistLogs, Cmd::HelpCmd, Cmd::Home, Cmd::Info, Cmd::InstallCmd, Cmd::Leaves, Cmd::Link, Cmd::List, Cmd::Log, Cmd::Migrate, Cmd::Missing, Cmd::NodenvSync, Cmd::OptionsCmd, Cmd::Outdated, Cmd::Pin, Cmd::PostgresqlUpgradeDatabase, Cmd::Postinstall, Cmd::Prefix, Cmd::PyenvSync, Cmd::RbenvSync, Cmd::ReadallCmd, Cmd::Reinstall, Cmd::Repository, Cmd::SearchCmd, Cmd::TapCmd, Cmd::TapInfo, Cmd::UninstallCmd, Cmd::UnlinkCmd, Cmd::Unpin, Cmd::Untap, Cmd::UpdateReport, Cmd::UpgradeCmd, Cmd::Uses, DevCmd::Audit, DevCmd::Bottle, DevCmd::Bump, DevCmd::BumpCaskPr, DevCmd::BumpFormulaPr, DevCmd::BumpRevision, DevCmd::BumpUnversionedCasks, DevCmd::Cat, DevCmd::Command, DevCmd::Contributions, DevCmd::Create, DevCmd::DetermineTestRunners, DevCmd::DispatchBuildBottle, DevCmd::Edit, DevCmd::Extract, DevCmd::FormulaCmd, DevCmd::GenerateCaskApi, DevCmd::GenerateFormulaApi, DevCmd::GenerateManCompletions, DevCmd::InstallBundlerGems, DevCmd::Irb, DevCmd::Linkage, DevCmd::LivecheckCmd, DevCmd::PrAutomerge, DevCmd::PrPublish, DevCmd::PrPull, DevCmd::PrUpload, DevCmd::Prof, DevCmd::Release, DevCmd::Ruby, DevCmd::Sh, DevCmd::StyleCmd, DevCmd::TapNew, DevCmd::Test, DevCmd::Tests, DevCmd::Typecheck, DevCmd::Unbottled, DevCmd::Unpack, DevCmd::UpdateLicenseData, DevCmd::UpdateMaintainers, DevCmd::UpdatePythonResources, DevCmd::UpdateSponsors, DevCmd::UpdateTest, DevCmd::VendorGems

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV.freeze) ⇒ void

Parameters:



44
45
46
# File 'abstract_command.rb', line 44

def initialize(argv = ARGV.freeze)
  @args = T.let(self.class.parser.parse(argv), CLI::Args)
end

Instance Attribute Details

#argsCLI::Args (readonly)

Returns:



41
42
43
# File 'abstract_command.rb', line 41

def args
  @args
end

Class Method Details

.command(name) ⇒ T.class_of(AbstractCommand)?

Returns the AbstractCommand subclass associated with the brew CLI command name.

Parameters:

Returns:

  • (T.class_of(AbstractCommand), nil)

    the AbstractCommand subclass associated with the brew CLI command name.



27
# File 'abstract_command.rb', line 27

def command(name) = subclasses.find { _1.command_name == name }

.command_nameString

Returns:



23
# File 'abstract_command.rb', line 23

def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-").delete_suffix("-cmd")

.parserCLI::Parser

Returns:



30
# File 'abstract_command.rb', line 30

def parser = CLI::Parser.new(self, &@parser_block)

Instance Method Details

#runvoid

This method is abstract.

This method returns an undefined value.



49
# File 'abstract_command.rb', line 49

def run; end