Class: Tapioca::Compilers::SubcommandArgs

Inherits:
Dsl::Compiler
  • Object
show all
Defined in:
sorbet/tapioca/compilers/subcommand_args.rb

Constant Summary collapse

ConstantType =
type_member { { fixed: T.class_of(Homebrew::AbstractSubcommand) } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsEnumerable<T.class_of(Homebrew::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.

Returns:



14
15
16
17
18
19
20
# File 'sorbet/tapioca/compilers/subcommand_args.rb', line 14

def self.gather_constants
  # require all the commands to ensure the subcommand subclasses are defined
  ["cmd", "dev-cmd"].each do |dir|
    Dir[File.join(__dir__, "../../../#{dir}", "*.rb")].each { require(it) }
  end
  Homebrew::AbstractSubcommand.subclasses
end

Instance Method Details

#decoratevoid

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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'sorbet/tapioca/compilers/subcommand_args.rb', line 23

def decorate
  command = constant.command
  command_args_class_name = command.args_class&.name
  raise "#{command} has no `Args` class; does it call `cmd_args`?" if command_args_class_name.nil?

  # The command's own methods are also defined on this shared `Args` instance,
  # so they must be filtered out here rather than read via `.methods(false)`.
  parser = command.parser
  method_names = Args.subcommand_method_names(parser, constant.subcommand_name)

  args_module = constant.args_module
  args_module_name = args_module.name
  raise "#{args_module} has no name" if args_module_name.nil?

  root.create_path(args_module) do |klass|
    Args.create_args_methods(klass, parser, method_names)
  end
  root.create_path(constant) do |klass|
    klass.create_method("args", return_type: "T.all(#{command_args_class_name}, #{args_module_name})")
  end
end