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.
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, #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.
73 74 75 76 77 78 79 |
# File 'abstract_subcommand.rb', line 73 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.
70 71 72 |
# File 'abstract_subcommand.rb', line 70 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.
91 92 93 |
# File 'abstract_subcommand.rb', line 91 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.
82 83 84 |
# File 'abstract_subcommand.rb', line 82 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.
88 89 90 |
# File 'abstract_subcommand.rb', line 88 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.
85 86 87 |
# File 'abstract_subcommand.rb', line 85 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 |
# 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 || [], 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.
97 |
# File 'abstract_subcommand.rb', line 97 def run; end |