2024-03-03 15:32:30 -08:00
|
|
|
# typed: strong
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-04 07:51:43 -08:00
|
|
|
require "command_registry"
|
|
|
|
|
2024-03-03 15:32:30 -08:00
|
|
|
module Homebrew
|
|
|
|
class AbstractCommand
|
|
|
|
extend T::Helpers
|
|
|
|
|
|
|
|
abstract!
|
|
|
|
|
|
|
|
class << self
|
|
|
|
# registers subclasses for lookup by command name
|
|
|
|
sig { params(subclass: T.class_of(AbstractCommand)).void }
|
|
|
|
def inherited(subclass)
|
|
|
|
super
|
2024-03-04 07:51:43 -08:00
|
|
|
CommandRegistry.register(subclass)
|
2024-03-03 15:32:30 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
sig { returns(String) }
|
|
|
|
def command_name = T.must(name).split("::").fetch(-1).downcase
|
|
|
|
end
|
|
|
|
|
|
|
|
# @note because `Args` makes use `OpenStruct`, subclasses may need to use a tapioca compiler,
|
|
|
|
# hash accessors, args.rbi, or other means to make this work with legacy commands:
|
|
|
|
sig { returns(Homebrew::CLI::Args) }
|
|
|
|
attr_reader :args
|
|
|
|
|
|
|
|
sig { void }
|
|
|
|
def initialize
|
|
|
|
@args = T.let(raw_args.parse, Homebrew::CLI::Args)
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { abstract.returns(CLI::Parser) }
|
|
|
|
def raw_args; end
|
|
|
|
|
|
|
|
sig { abstract.void }
|
|
|
|
def run; end
|
|
|
|
end
|
|
|
|
end
|