Class: Tapioca::Compilers::Args
- Defined in:
- sorbet/tapioca/compilers/args.rb
Constant Summary collapse
- GLOBAL_OPTIONS =
T.let( Homebrew::CLI::Parser..map do |short_option, long_option, _| [short_option, long_option].map { "#{Homebrew::CLI::Parser.option_to_name(_1)}?" } end.flatten.freeze, T::Array[String] )
- Parsable =
T.type_alias { T.any(T.class_of(Homebrew::CLI::Args), T.class_of(Homebrew::AbstractCommand)) }
- ConstantType =
type_member { { fixed: Parsable } }
Class Method Summary collapse
Instance Method Summary collapse
- #args_table(parser) ⇒ Array<Symbol> private
- #comma_arrays(parser) ⇒ Array<Symbol> private
- #decorate ⇒ void private
- #get_return_type(method_name, comma_array_methods) ⇒ String private
Class Method Details
.gather_constants ⇒ Enumerable<Parsable>
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.
19 20 21 22 23 24 25 |
# File 'sorbet/tapioca/compilers/args.rb', line 19 def self.gather_constants # require all the commands to ensure the command subclasses are defined ["cmd", "dev-cmd"].each do |dir| Dir[File.join(__dir__, "../../../#{dir}", "*.rb")].each { require(_1) } end Homebrew::AbstractCommand.subclasses end |
Instance Method Details
#args_table(parser) ⇒ Array<Symbol>
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.
43 |
# File 'sorbet/tapioca/compilers/args.rb', line 43 def args_table(parser) = parser.args.methods(false) |
#comma_arrays(parser) ⇒ Array<Symbol>
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.
46 47 48 49 |
# File 'sorbet/tapioca/compilers/args.rb', line 46 def comma_arrays(parser) parser.instance_variable_get(:@non_global_processed_options) .filter_map { |k, v| parser.option_to_name(k).to_sym if v == :comma_array } end |
#decorate ⇒ 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'sorbet/tapioca/compilers/args.rb', line 28 def decorate cmd = T.cast(constant, T.class_of(Homebrew::AbstractCommand)) # This is a dummy class to make the `brew` command parsable return if cmd == Homebrew::Cmd::Brew 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 |
#get_return_type(method_name, comma_array_methods) ⇒ 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.
52 53 54 55 56 57 58 59 60 |
# File 'sorbet/tapioca/compilers/args.rb', line 52 def get_return_type(method_name, comma_array_methods) if comma_array_methods.include?(method_name) "T.nilable(T::Array[String])" elsif method_name.end_with?("?") "T::Boolean" else "T.nilable(String)" end end |