Merge pull request #17920 from Homebrew/tapioca-args-fix

This commit is contained in:
Patrick Linnane 2024-07-31 09:53:41 -07:00 committed by GitHub
commit 1af028f18a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 29 deletions

View File

@ -1,8 +0,0 @@
# typed: true
# DO NOT EDIT MANUALLY
# This is an autogenerated file for dynamic methods in `Homebrew::CLI::Args`.
# Please instead update this file by running `bin/tapioca dsl Homebrew::CLI::Args`.
class Homebrew::CLI::Args; end

View File

@ -190,7 +190,7 @@ module Homebrew::EnvConfig
sig { returns(String) } sig { returns(String) }
def livecheck_watchlist; end def livecheck_watchlist; end
sig { returns(String) } sig { returns(T.nilable(::String)) }
def lock_context; end def lock_context; end
sig { returns(String) } sig { returns(String) }

View File

@ -21,31 +21,22 @@ module Tapioca
sig { override.returns(T::Enumerable[Parsable]) } sig { override.returns(T::Enumerable[Parsable]) }
def self.gather_constants def self.gather_constants
# require all the commands to ensure the _arg methods are defined # require all the commands to ensure the command subclasses are defined
["cmd", "dev-cmd"].each do |dir| ["cmd", "dev-cmd"].each do |dir|
Dir[File.join(__dir__, "../../../#{dir}", "*.rb")].each { require(_1) } Dir[File.join(__dir__, "../../../#{dir}", "*.rb")].each { require(_1) }
end end
[Homebrew::CLI::Args] + Homebrew::AbstractCommand.subclasses Homebrew::AbstractCommand.subclasses
end end
sig { override.void } sig { override.void }
def decorate def decorate
if constant == Homebrew::CLI::Args cmd = T.cast(constant, T.class_of(Homebrew::AbstractCommand))
root.create_path(Homebrew::CLI::Args) do |klass| args_class_name = T.must(T.must(cmd.args_class).name)
Homebrew.methods(false).select { _1.end_with?("_args") }.each do |args_method_name| root.create_class(args_class_name, superclass_name: "Homebrew::CLI::Args") do |klass|
parser = Homebrew.method(args_method_name).call create_args_methods(klass, cmd.parser)
create_args_methods(klass, parser) end
end root.create_path(constant) do |klass|
end klass.create_method("args", return_type: args_class_name)
else
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
end end
@ -80,8 +71,6 @@ module Tapioca
args_table(parser).each do |method_name, value| args_table(parser).each do |method_name, value|
method_name_str = method_name.to_s method_name_str = method_name.to_s
next if GLOBAL_OPTIONS.include?(method_name_str) next if GLOBAL_OPTIONS.include?(method_name_str)
# some args are used in multiple commands (this is ok as long as they have the same type)
next if klass.nodes.any? { T.cast(_1, RBI::Method).name == method_name_str }
return_type = get_return_type(method_name, value, comma_array_methods) return_type = get_return_type(method_name, value, comma_array_methods)
klass.create_method(method_name_str, return_type:) klass.create_method(method_name_str, return_type:)