Spec-Zone.ru › Homebrew

Class: Homebrew::AbstractCommand Abstract

Inherits:
Object
  • Object
  • Homebrew::AbstractCommand
show all
Extended by:
T::Helpers
Includes:
Utils::Output::Mixin
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 instance method 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::Alias, Cmd::Analytics, Cmd::AsConsoleUser, Cmd::Autoremove, Cmd::Brew, Cmd::Bundle, Cmd::Cache, Cmd::Caskroom, Cmd::Casks, Cmd::Cellar, Cmd::CleanupCmd, Cmd::Command, Cmd::CommandNotFoundInit, Cmd::CommandsCmd, Cmd::CompletionsCmd, Cmd::Config, Cmd::Deps, Cmd::Desc, Cmd::Developer, Cmd::Docs, Cmd::Doctor, Cmd::Env, Cmd::Exec, Cmd::FetchCmd, Cmd::Formulae, Cmd::GistLogs, Cmd::HelpCmd, Cmd::Home, Cmd::Info, Cmd::InstallCmd, Cmd::Leaves, Cmd::Link, Cmd::List, Cmd::Log, Cmd::McpServerCmd, Cmd::Migrate, Cmd::Missing, Cmd::NodenvSync, Cmd::OptionsCmd, Cmd::Outdated, Cmd::Pin, Cmd::Postinstall, Cmd::Prefix, Cmd::PyenvSync, Cmd::RbenvSync, Cmd::ReadallCmd, Cmd::Reinstall, Cmd::Repository, Cmd::SandboxExec, Cmd::SearchCmd, Cmd::Services, Cmd::SetupRuby, Cmd::SetupSandbox, Cmd::Shellenv, Cmd::Source, Cmd::TabCmd, Cmd::TapCmd, Cmd::TapInfo, Cmd::Taps, Cmd::TestBotCmd, Cmd::Trust, Cmd::Unalias, Cmd::UninstallCmd, Cmd::UnlinkCmd, Cmd::Unpin, Cmd::Untap, Cmd::Untrust, Cmd::Update, Cmd::UpdateIfNeeded, Cmd::UpdateReport, Cmd::UpdateReset, Cmd::UpgradeCmd, Cmd::Uses, Cmd::VendorInstall, Cmd::Version, Cmd::VersionInstall, Cmd::WhichFormula, DevCmd::Audit, DevCmd::Bottle, DevCmd::Bump, DevCmd::BumpCaskPr, DevCmd::BumpCompatibilityVersion, DevCmd::BumpFormulaPr, DevCmd::BumpRevision, DevCmd::BumpUnversionedCasks, DevCmd::Cat, DevCmd::Contributions, DevCmd::Create, DevCmd::Debugger, DevCmd::DetermineTestRunners, DevCmd::DispatchBuildBottle, DevCmd::Edit, DevCmd::Extract, DevCmd::FormulaAnalytics, DevCmd::FormulaCmd, DevCmd::GenerateAnalyticsApi, DevCmd::GenerateCaskApi, DevCmd::GenerateCaskCiMatrix, DevCmd::GenerateFormulaApi, DevCmd::GenerateInternalApi, DevCmd::GenerateManCompletions, DevCmd::GenerateZap, DevCmd::InstallBundlerGems, DevCmd::Irb, DevCmd::Lgtm, DevCmd::Linkage, DevCmd::LivecheckCmd, DevCmd::PrAutomerge, DevCmd::PrPublish, DevCmd::PrPull, DevCmd::PrUpload, DevCmd::Prof, DevCmd::Release, DevCmd::Rubocop, DevCmd::Ruby, DevCmd::Rubydoc, DevCmd::Sh, DevCmd::StyleCmd, DevCmd::TapNew, DevCmd::Test, DevCmd::Tests, DevCmd::Typecheck, DevCmd::Unbottled, DevCmd::Unpack, DevCmd::UpdateLicenseData, DevCmd::UpdateMaintainers, DevCmd::UpdatePerlResources, DevCmd::UpdatePortableRuby, DevCmd::UpdatePythonResources, DevCmd::UpdateSponsors, DevCmd::UpdateTest, DevCmd::VendorGems, DevCmd::Verify, DevCmd::WhichUpdate

Class Attribute Summary collapse

  • .args_class ⇒ T.class_of(CLI::Args)? readonly private

Instance Attribute Summary collapse

  • #args ⇒ CLI::Args readonly private

Class Method Summary collapse

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

    The AbstractCommand subclass associated with the brew CLI command name.

  • .command_name ⇒ String private
  • .dev_cmd? ⇒ Boolean private
  • .parser ⇒ CLI::Parser private
  • .ruby_cmd? ⇒ Boolean private

Instance Method Summary collapse

  • #initialize(argv = ARGV.freeze) ⇒ void constructor private
  • #run ⇒ void abstract

    This method will be invoked when the command is run.

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_upgradable, #pretty_warning

Constructor Details

#initialize(argv = ARGV.freeze) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • argv (Array<String>) (defaults to: ARGV.freeze)


69
70
71
# File 'abstract_command.rb', line 69

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

Class Attribute Details

.args_class ⇒ T.class_of(CLI::Args)? (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (T.class_of(CLI::Args), nil)


29
30
31
# File 'abstract_command.rb', line 29

def args_class
  @args_class
end

Instance Attribute Details

#args ⇒ CLI::Args (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (CLI::Args)


66
67
68
# File 'abstract_command.rb', line 66

def args
  @args
end

Class Method Details

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

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

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

Parameters:

  • name (String)

Returns:

  • (T.class_of(AbstractCommand), nil) —

    the AbstractCommand subclass associated with the brew CLI command name.



42
# File 'abstract_command.rb', line 42

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

.command_name ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (String)


32
33
34
35
36
37
38
# File 'abstract_command.rb', line 32

def command_name
  require "utils"

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

.dev_cmd? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


45
# File 'abstract_command.rb', line 45

def dev_cmd? = T.must(name).start_with?("Homebrew::DevCmd")

.parser ⇒ CLI::Parser

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (CLI::Parser)


51
# File 'abstract_command.rb', line 51

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

.ruby_cmd? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


48
# File 'abstract_command.rb', line 48

def ruby_cmd? = !include?(Homebrew::ShellCommand)

Instance Method Details

#run ⇒ void

This method is abstract.

This method returns an undefined value.

This method will be invoked when the command is run.



77
# File 'abstract_command.rb', line 77

def run; end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Homebrew/AbstractCommand.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API