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::RegenerateUuidSubcommand, 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 ⇒ T.untyped readonly private
- #cleanup ⇒ Boolean readonly private
- #context ⇒ T.untyped readonly private
- #quiet ⇒ Boolean readonly private
- #targets ⇒ T.untyped readonly private
Class Method Summary collapse
- .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_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #pretty_upgradable
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.
86 87 88 89 90 91 92 |
# File 'abstract_subcommand.rb', line 86 def initialize(args, context: nil, targets: nil, quiet: false, cleanup: true) @args = args @context = context @targets = targets @quiet = quiet @cleanup = cleanup end |
Instance Attribute Details
#args ⇒ 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.
83 84 85 |
# File 'abstract_subcommand.rb', line 83 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.
104 105 106 |
# File 'abstract_subcommand.rb', line 104 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.
95 96 97 |
# File 'abstract_subcommand.rb', line 95 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.
101 102 103 |
# File 'abstract_subcommand.rb', line 101 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.
98 99 100 |
# File 'abstract_subcommand.rb', line 98 def targets @targets end |
Class Method Details
.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.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'abstract_subcommand.rb', line 47 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.
40 41 42 43 44 |
# File 'abstract_subcommand.rb', line 40 def define_all(parser, command:) subcommands_for(command).each do |subcommand| subcommand.define(parser) 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 |
# File 'abstract_subcommand.rb', line 32 def subcommands_for(command) namespace = "#{command.name}::" 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.
110 |
# File 'abstract_subcommand.rb', line 110 def run; end |