Class: Homebrew::AbstractSubcommand Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers
Includes:
Utils::Output::Mixin
Defined in:
abstract_subcommand.rb

Overview

This class is abstract.

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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • args (T.untyped)
  • context (T.untyped) (defaults to: nil)
  • targets (T.untyped) (defaults to: nil)
  • quiet (Boolean) (defaults to: false)
  • cleanup (Boolean) (defaults to: true)


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

#argsT.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.

Returns:

  • (T.untyped)


70
71
72
# File 'abstract_subcommand.rb', line 70

def args
  @args
end

#cleanupBoolean (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:

  • (Boolean)


91
92
93
# File 'abstract_subcommand.rb', line 91

def cleanup
  @cleanup
end

#contextT.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.

Returns:

  • (T.untyped)


82
83
84
# File 'abstract_subcommand.rb', line 82

def context
  @context
end

#quietBoolean (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:

  • (Boolean)


88
89
90
# File 'abstract_subcommand.rb', line 88

def quiet
  @quiet
end

#targetsT.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.

Returns:

  • (T.untyped)


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.

Parameters:

Raises:

  • (TypeError)


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.

Parameters:



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_nameString

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:

Raises:

  • (TypeError)


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.

Parameters:

Returns:



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

#runvoid

This method is abstract.

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