Class: Homebrew::AbstractSubcommand Abstract
Overview
It cannot be directly instantiated. Subclasses must implement the abstract methods below.
Subclass this to implement a subcommand for a brew command.
Direct Known Subclasses
Cmd::Analytics::OffSubcommand, Cmd::Analytics::OnSubcommand, Cmd::Analytics::StateSubcommand, Cmd::Bundle::AddSubcommand, Cmd::Bundle::CheckSubcommand, Cmd::Bundle::CleanupSubcommand, Cmd::Bundle::DumpSubcommand, Cmd::Bundle::EditSubcommand, Cmd::Bundle::EnvSubcommand, Cmd::Bundle::ExecSubcommand, Cmd::Bundle::InstallSubcommand, Cmd::Bundle::ListSubcommand, Cmd::Bundle::RemoveSubcommand, Cmd::Bundle::ShSubcommand, Cmd::CompletionsCmd::LinkSubcommand, Cmd::CompletionsCmd::StateSubcommand, Cmd::CompletionsCmd::UnlinkSubcommand, Cmd::Developer::OffSubcommand, Cmd::Developer::OnSubcommand, Cmd::Developer::StateSubcommand, Cmd::Services::CleanupSubcommand, Cmd::Services::InfoSubcommand, Cmd::Services::KillSubcommand, Cmd::Services::ListSubcommand, Cmd::Services::RestartSubcommand, Cmd::Services::RunSubcommand, Cmd::Services::StartSubcommand, Cmd::Services::StopSubcommand
Instance Attribute Summary collapse
- #args ⇒ CLI::Args readonly private
- #cleanup ⇒ Boolean readonly private
- #context ⇒ T.untyped readonly private
- #quiet ⇒ Boolean readonly private
- #targets ⇒ T.untyped readonly private
Class Method Summary collapse
-
.args_module ⇒ T::Module[T.anything]
private
A module
extended onto this subcommand'sargsin#initialize, sois_a?genuinely holds for the type named in the generated RBI (seeTapioca::Compilers::SubcommandArgs) instead of only approximating it statically. - .command ⇒ T.class_of(Homebrew::AbstractCommand) private
- .define(parser) ⇒ void private
- .define_all(parser, command:) ⇒ void private
- .subcommand_name ⇒ String private
- .subcommands_for(command) ⇒ Array<T.class_of(AbstractSubcommand)> private
Instance Method Summary collapse
- #initialize(args, context: nil, targets: nil, quiet: false, cleanup: true) ⇒ void constructor private
-
#run ⇒ void
abstract
This method will be invoked when the subcommand 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_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(args, context: nil, targets: nil, quiet: false, cleanup: true) ⇒ 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.
105 106 107 108 109 110 111 112 113 |
# File 'abstract_subcommand.rb', line 105 def initialize(args, context: nil, targets: nil, quiet: false, cleanup: true) # `args` is frozen by `CLI::Parser#parse`, so `extend` needs an unfrozen clone # (which, unlike `dup`, keeps the singleton methods the parser defined on it). @args = T.let(args.clone(freeze: false).extend(self.class.args_module).freeze, CLI::Args) @context = context @targets = targets @quiet = quiet @cleanup = cleanup 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.
102 103 104 |
# File 'abstract_subcommand.rb', line 102 def args @args end |
#cleanup ⇒ Boolean (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.
125 126 127 |
# File 'abstract_subcommand.rb', line 125 def cleanup @cleanup end |
#context ⇒ T.untyped (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.
116 117 118 |
# File 'abstract_subcommand.rb', line 116 def context @context end |
#quiet ⇒ Boolean (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.
122 123 124 |
# File 'abstract_subcommand.rb', line 122 def quiet @quiet end |
#targets ⇒ T.untyped (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.
119 120 121 |
# File 'abstract_subcommand.rb', line 119 def targets @targets end |
Class Method Details
.args_module ⇒ T::Module[T.anything]
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.
A module extended onto this subcommand's args in #initialize, so is_a?
genuinely holds for the type named in the generated RBI (see
Tapioca::Compilers::SubcommandArgs) instead of only approximating it statically.
53 54 55 |
# File 'abstract_subcommand.rb', line 53 def args_module @args_module ||= T.let(const_set(:Args, Module.new), T.nilable(T::Module[T.anything])) end |
.command ⇒ T.class_of(Homebrew::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.
42 43 44 45 46 47 |
# File 'abstract_subcommand.rb', line 42 def command found = Homebrew::AbstractCommand.subclasses.find { |candidate| subcommands_for(candidate).include?(self) } raise TypeError, "#{self} is not nested under a `Homebrew::AbstractCommand`" if found.nil? found end |
.define(parser) ⇒ 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.
This method returns an undefined value.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'abstract_subcommand.rb', line 66 def define(parser) parser_block = @parser_block raise TypeError, "subcommand arguments have not been defined" if parser_block.nil? parser.subcommand( subcommand_name, aliases: @aliases || [], alias_options: @alias_options || {}, default: @default || false, ) do instance_eval(&parser_block) end end |
.define_all(parser, command:) ⇒ 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.
This method returns an undefined value.
58 59 60 61 62 63 |
# File 'abstract_subcommand.rb', line 58 def define_all(parser, command:) subcommands_for(command).each do |subcommand| subcommand.define(parser) subcommand.args_module end end |
.subcommand_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.
20 21 22 23 24 25 26 27 28 29 |
# File 'abstract_subcommand.rb', line 20 def subcommand_name require "utils" class_name = name raise TypeError, "anonymous subcommands do not have names" if class_name.nil? Utils.underscore(class_name.split("::").fetch(-1)) .tr("_", "-") .delete_suffix("-subcommand") end |
.subcommands_for(command) ⇒ Array<T.class_of(AbstractSubcommand)>
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.
32 33 34 35 36 37 38 39 |
# File 'abstract_subcommand.rb', line 32 def subcommands_for(command) namespace = "#{command.name}::" # Qualified so this behaves the same whether called on `AbstractSubcommand` # itself or (as `command` does below) on one of its subclasses. Homebrew::AbstractSubcommand.subclasses.select do |subcommand| subcommand.name&.start_with?(namespace) end end |
Instance Method Details
#run ⇒ void
This method returns an undefined value.
This method will be invoked when the subcommand is run.
131 |
# File 'abstract_subcommand.rb', line 131 def run; end |