Make cmd_args block non-nilable
This commit is contained in:
parent
625206b0bd
commit
131a5421a5
@ -6,6 +6,7 @@ module Homebrew
|
||||
# module, because:
|
||||
# - Each Command lives in an isolated namespace.
|
||||
# - Each Command implements a defined interface.
|
||||
# - `args` is available as an ivar, and thus does not need to be passed as an argument to helper methods.
|
||||
#
|
||||
# To subclass, implement a `run` method and provide a `cmd_args` block to document the command and its allowed args.
|
||||
# To generate method signatures for command args, run `brew typecheck --update`.
|
||||
@ -27,20 +28,21 @@ module Homebrew
|
||||
|
||||
private
|
||||
|
||||
sig { params(block: T.nilable(T.proc.bind(CLI::Parser).void)).void }
|
||||
sig { params(block: T.proc.bind(CLI::Parser).void).void }
|
||||
def cmd_args(&block)
|
||||
@parser = T.let(CLI::Parser.new(&block), T.nilable(CLI::Parser))
|
||||
end
|
||||
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(CLI::Args) }
|
||||
attr_reader :args
|
||||
|
||||
sig { params(argv: T::Array[String]).void }
|
||||
def initialize(argv = ARGV.freeze)
|
||||
@args = T.let(T.must(self.class.parser).parse(argv), CLI::Args)
|
||||
parser = self.class.parser
|
||||
raise "Commands must include a `cmd_args` block" if parser.nil?
|
||||
|
||||
@args = T.let(parser.parse(argv), CLI::Args)
|
||||
end
|
||||
|
||||
sig { abstract.void }
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# require 'tapioca'
|
||||
require "tapioca/dsl"
|
||||
require_relative "../../../../sorbet/tapioca/compilers/args"
|
||||
require "sorbet/tapioca/compilers/args"
|
||||
|
||||
RSpec.describe Tapioca::Compilers::Args do
|
||||
let(:compiler) { described_class.new(Tapioca::Dsl::Pipeline.new(requested_constants: []), RBI::Tree.new, Homebrew) }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user