Individually namespace args for each command
This commit is contained in:
parent
54bea636b4
commit
7bfa552702
@ -19,6 +19,9 @@ module Homebrew
|
||||
abstract!
|
||||
|
||||
class << self
|
||||
sig { returns(T.nilable(T.class_of(CLI::Args))) }
|
||||
attr_reader :args_class
|
||||
|
||||
sig { returns(String) }
|
||||
def command_name = Utils.underscore(T.must(name).split("::").fetch(-1)).tr("_", "-").delete_suffix("-cmd")
|
||||
|
||||
@ -37,6 +40,7 @@ module Homebrew
|
||||
sig { params(block: T.proc.bind(CLI::Parser).void).void }
|
||||
def cmd_args(&block)
|
||||
@parser_block = T.let(block, T.nilable(T.proc.void))
|
||||
@args_class = T.let(const_set(:Args, Class.new(CLI::Args)), T.nilable(T.class_of(CLI::Args)))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ module Cask
|
||||
|
||||
sig { params(args: Homebrew::CLI::Args).returns(T.attached_class) }
|
||||
def self.from_args(args)
|
||||
args = T.unsafe(args)
|
||||
new(explicit: {
|
||||
appdir: args.appdir,
|
||||
keyboard_layoutdir: args.keyboard_layoutdir,
|
||||
|
||||
@ -19,4 +19,25 @@ class Homebrew::CLI::Args
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def verbose?; end
|
||||
|
||||
# FIXME: The methods below are not defined by Args, but are valid because Args inherits from OpenStruct
|
||||
# We should instead be using type guards to check if the method is defined on the object before calling it
|
||||
|
||||
sig { returns(T.nilable(String)) }
|
||||
def arch; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def build_from_source?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def cask?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def formula?; end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def include_test?; end
|
||||
|
||||
sig { returns(T.nilable(String)) }
|
||||
def os; end
|
||||
end
|
||||
|
||||
@ -152,7 +152,7 @@ module Homebrew
|
||||
# Disable default handling of `--help` switch.
|
||||
@parser.base.long.delete("help")
|
||||
|
||||
@args = T.let(Homebrew::CLI::Args.new, Homebrew::CLI::Args)
|
||||
@args = T.let((cmd&.args_class || Args).new, Args)
|
||||
|
||||
if cmd
|
||||
@command_name = T.let(cmd.command_name, String)
|
||||
|
||||
@ -48,7 +48,8 @@ module Homebrew
|
||||
|
||||
HOMEBREW_LIBRARY_PATH.cd do
|
||||
if update
|
||||
safe_system "bundle", "exec", "tapioca", "dsl"
|
||||
workers = args.debug? ? ["--workers=1"] : []
|
||||
safe_system "bundle", "exec", "tapioca", "dsl", *workers
|
||||
# Prefer adding args here: Library/Homebrew/sorbet/tapioca/config.yml
|
||||
tapioca_args = args.update_all? ? ["--all"] : []
|
||||
|
||||
|
||||
@ -38,9 +38,13 @@ module Tapioca
|
||||
end
|
||||
end
|
||||
else
|
||||
root.create_path(Homebrew::CLI::Args) do |klass|
|
||||
parser = T.cast(constant, T.class_of(Homebrew::AbstractCommand)).parser
|
||||
create_args_methods(klass, parser)
|
||||
cmd = T.cast(constant, T.class_of(Homebrew::AbstractCommand))
|
||||
args_class_name = T.must(T.must(cmd.args_class).name)
|
||||
root.create_class(args_class_name, superclass_name: "Homebrew::CLI::Args") do |klass|
|
||||
create_args_methods(klass, cmd.parser)
|
||||
end
|
||||
root.create_path(constant) do |klass|
|
||||
klass.create_method("args", return_type: args_class_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user