diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 46e926e83aee7..96c2f71e1f6b2 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -408,10 +408,6 @@ Style/NumericLiterals: Style/OpenStructUse: Exclude: - "Taps/**/*" - # TODO: This is a pre-existing violation and should be corrected - # to define methods so that call sites can be type-checked. - - "Homebrew/cli/args.rb" - - "Homebrew/cli/args.rbi" Style/OptionalBooleanParameter: AllowedMethods: diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index e34e4417975cd..ae8c2539fb0aa 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -42,6 +42,8 @@ def self.defaults sig { params(args: Homebrew::CLI::Args).returns(T.attached_class) } def self.from_args(args) + # FIXME: T.unsafe is a workaround for methods that are only defined when `cask_options` + # is invoked on the parser. (These could be captured by a DSL compiler instead.) args = T.unsafe(args) new(explicit: { appdir: args.appdir, diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index f391a8726e465..f3358bfc10881 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -1,26 +1,23 @@ # typed: strict # frozen_string_literal: true -require "ostruct" - module Homebrew module CLI - class Args < OpenStruct + class Args # Represents a processed option. The array elements are: # 0: short option name (e.g. "-d") # 1: long option name (e.g. "--debug") # 2: option description (e.g. "Print debugging information") # 3: whether the option is hidden OptionsType = T.type_alias { T::Array[[String, T.nilable(String), String, T::Boolean]] } + sig { returns(T::Array[String]) } - attr_reader :options_only, :flags_only + attr_reader :options_only, :flags_only, :remaining sig { void } def initialize require "cli/named_args" - super - @cli_args = T.let(nil, T.nilable(T::Array[String])) @processed_options = T.let([], OptionsType) @options_only = T.let([], T::Array[String]) @@ -30,30 +27,41 @@ def initialize # Can set these because they will be overwritten by freeze_named_args! # (whereas other values below will only be overwritten if passed). - self[:named] = NamedArgs.new(parent: self) - self[:remaining] = [] + @named = T.let(NamedArgs.new(parent: self), T.nilable(NamedArgs)) + @remaining = T.let([], T::Array[String]) end sig { params(remaining_args: T::Array[T.any(T::Array[String], String)]).void } - def freeze_remaining_args!(remaining_args) - self[:remaining] = remaining_args.freeze - end + def freeze_remaining_args!(remaining_args) = @remaining.replace(remaining_args).freeze sig { params(named_args: T::Array[String], cask_options: T::Boolean, without_api: T::Boolean).void } def freeze_named_args!(named_args, cask_options:, without_api:) - options = {} - options[:force_bottle] = true if self[:force_bottle?] - options[:override_spec] = :head if self[:HEAD?] - options[:flags] = flags_only unless flags_only.empty? - self[:named] = NamedArgs.new( - *named_args.freeze, - parent: self, - cask_options:, - without_api:, - **options, + @named = T.let( + NamedArgs.new( + *named_args.freeze, + cask_options:, + flags: flags_only, + force_bottle: @table[:force_bottle?] || false, + override_spec: @table[:HEAD?] ? :head : nil, + parent: self, + without_api:, + ), + T.nilable(NamedArgs), ) end + sig { params(name: Symbol, value: T.untyped).void } + def set_arg(name, value) + @table[name] = value + end + + sig { override.params(_blk: T.nilable(T.proc.params(x: T.untyped).void)).returns(T.untyped) } + def tap(&_blk) + return super if block_given? # Object#tap + + @table[:tap] + end + sig { params(processed_options: OptionsType).void } def freeze_processed_options!(processed_options) # Reset cache values reliant on processed_options @@ -69,7 +77,7 @@ def freeze_processed_options!(processed_options) sig { returns(NamedArgs) } def named require "formula" - self[:named] + T.must(@named) end sig { returns(T::Boolean) } @@ -77,7 +85,7 @@ def no_named? = named.empty? sig { returns(T::Array[String]) } def build_from_source_formulae - if build_from_source? || self[:HEAD?] || self[:build_bottle?] + if @table[:build_from_source?] || @table[:HEAD?] || @table[:build_bottle?] named.to_formulae.map(&:full_name) else [] @@ -86,7 +94,7 @@ def build_from_source_formulae sig { returns(T::Array[String]) } def include_test_formulae - if include_test? + if @table[:include_test?] named.to_formulae.map(&:full_name) else [] @@ -109,9 +117,9 @@ def context sig { returns(T.nilable(Symbol)) } def only_formula_or_cask - if formula? && !cask? + if @table[:formula?] && !@table[:cask?] :formula - elsif cask? && !formula? + elsif @table[:cask?] && !@table[:formula?] :cask end end @@ -120,7 +128,7 @@ def only_formula_or_cask def os_arch_combinations skip_invalid_combinations = false - oses = case (os_sym = os&.to_sym) + oses = case (os_sym = @table[:os]&.to_sym) when nil [SimulateSystem.current_os] when :all @@ -131,7 +139,7 @@ def os_arch_combinations [os_sym] end - arches = case (arch_sym = arch&.to_sym) + arches = case (arch_sym = @table[:arch]&.to_sym) when nil [SimulateSystem.current_arch] when :all @@ -174,24 +182,6 @@ def cli_args end end.freeze end - - sig { params(method_name: Symbol, _include_private: T::Boolean).returns(T::Boolean) } - def respond_to_missing?(method_name, _include_private = false) - @table.key?(method_name) - end - - sig { params(method_name: Symbol, args: T.untyped).returns(T.untyped) } - def method_missing(method_name, *args) - return_value = super - - # Once we are frozen, verify any arg method calls are already defined in the table. - # The default OpenStruct behaviour is to return nil for anything unknown. - if frozen? && args.empty? && !@table.key?(method_name) - raise NoMethodError, "CLI arg for `#{method_name}` is not declared for this command" - end - - return_value - end end end end diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index 11451fdb558e7..7c161fd39becc 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -14,30 +14,6 @@ class Homebrew::CLI::Args sig { returns(T::Boolean) } def quiet?; end - sig { returns(T::Array[String]) } - def remaining; end - 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 diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index b1a9465ee481b..d74ad34cbec6d 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -252,7 +252,7 @@ def comma_array(name, description: nil, hidden: false) description = option_description(description, name, hidden:) process_option(name, description, type: :comma_array, hidden:) @parser.on(name, OptionParser::REQUIRED_ARGUMENT, Array, *wrap_option_desc(description)) do |list| - @args[option_to_name(name)] = list + set_args_method(option_to_name(name).to_sym, list) end end @@ -277,7 +277,7 @@ def flag(*names, description: nil, replacement: nil, depends_on: nil, hidden: fa # This odisabled should stick around indefinitely. odisabled "the `#{names.first}` flag", replacement unless replacement.nil? names.each do |name| - @args[option_to_name(name)] = option_value + set_args_method(option_to_name(name).to_sym, option_value) end end @@ -286,6 +286,17 @@ def flag(*names, description: nil, replacement: nil, depends_on: nil, hidden: fa end end + sig { params(name: Symbol, value: T.untyped).void } + def set_args_method(name, value) + @args.set_arg(name, value) + return if @args.respond_to?(name) + + @args.define_singleton_method(name) do + # We cannot reference the ivar directly due to https://github.com/sorbet/sorbet/issues/8106 + instance_variable_get(:@table).fetch(name) + end + end + sig { params(options: String).returns(T::Array[T::Array[String]]) } def conflicts(*options) @conflicts << options.map { |option| option_to_name(option) } @@ -558,24 +569,27 @@ def generate_banner def set_switch(*names, value:, from:) names.each do |name| @switch_sources[option_to_name(name)] = from - @args["#{option_to_name(name)}?"] = value + set_args_method(:"#{option_to_name(name)}?", value) end end sig { params(args: String).void } def disable_switch(*args) args.each do |name| - @args["#{option_to_name(name)}?"] = if name.start_with?("--[no-]") + result = if name.start_with?("--[no-]") nil else false end + set_args_method(:"#{option_to_name(name)}?", result) end end sig { params(name: String).returns(T::Boolean) } def option_passed?(name) - !!(@args[name.to_sym] || @args[:"#{name}?"]) + [name.to_sym, :"#{name}?"].any? do |method| + @args.public_send(method) if @args.respond_to?(method) + end end sig { params(desc: String).returns(T::Array[String]) } @@ -676,7 +690,7 @@ def process_option(*args, type:, hidden: false) disable_switch(*args) else args.each do |name| - @args[option_to_name(name)] = nil + set_args_method(option_to_name(name).to_sym, nil) end end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 9d0e6cf6bdc9b..7429daec5e2c0 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -108,7 +108,7 @@ def print_regex_help sig { returns(T::Boolean) } def search_package_manager - package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] } + package_manager = PACKAGE_MANAGERS.find { |name,| args.public_send(:"#{name}?") } return false if package_manager.nil? _, url = package_manager diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 21682ae9ed7cc..03d9599e6cbb3 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -125,7 +125,7 @@ def run audit_formulae, audit_casks = Homebrew.with_no_api_env do # audit requires full Ruby source if args.tap - Tap.fetch(T.must(args.tap)).then do |tap| + Tap.fetch(args.tap).then do |tap| [ tap.formula_files.map { |path| Formulary.factory(path) }, tap.cask_files.map { |path| Cask::CaskLoader.load(path) }, diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 4b2be96bc9c53..f635e5b22985a 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -86,7 +86,7 @@ def run Formulary.factory(qualified_name) end elsif args.tap - tap = Tap.fetch(T.must(args.tap)) + tap = Tap.fetch(args.tap) raise UsageError, "`--tap` requires `--auto` for official taps." if tap.official? formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index b2ffcbdb16205..b811ad4fe614f 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -60,7 +60,7 @@ def run formulae_and_casks_to_check = Homebrew.with_no_api_env do if args.tap - tap = Tap.fetch(T.must(args.tap)) + tap = Tap.fetch(args.tap) formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) } formulae + casks diff --git a/Library/Homebrew/extend/os/linux/cli/parser.rb b/Library/Homebrew/extend/os/linux/cli/parser.rb index e5fd59e146cb9..feb4eb2aabffe 100644 --- a/Library/Homebrew/extend/os/linux/cli/parser.rb +++ b/Library/Homebrew/extend/os/linux/cli/parser.rb @@ -11,13 +11,13 @@ module Parser sig { void } def set_default_options - args["formula?"] = true if args.respond_to?(:formula?) + args.set_arg(:formula?, true) end sig { void } def validate_options return unless args.respond_to?(:cask?) - return unless args.cask? + return unless T.unsafe(self).args.cask? # NOTE: We don't raise an error here because we don't want # to print the help page or a stack trace. diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/tap_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/tap_cmd.rbi index 2372f2207a684..63c82b860731e 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/tap_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/tap_cmd.rbi @@ -20,7 +20,7 @@ class Homebrew::Cmd::TapCmd::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def force?; end - sig { returns(T.nilable(String)) } + sig { returns(T::Boolean) } def force_auto_update?; end sig { returns(T::Boolean) } diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/audit.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/audit.rbi index 146719a333f8b..2665fe78c2c38 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/audit.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/audit.rbi @@ -71,7 +71,7 @@ class Homebrew::DevCmd::Audit::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def os; end - sig { returns(T.nilable(String)) } + sig { returns(T::Boolean) } def signing?; end sig { returns(T::Boolean) } @@ -80,9 +80,6 @@ class Homebrew::DevCmd::Audit::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def strict?; end - sig { returns(T.nilable(String)) } - def tap; end - sig { returns(T::Boolean) } def token_conflicts?; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi index a44d6ec9556a6..1e750628c45e3 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi @@ -49,7 +49,4 @@ class Homebrew::DevCmd::Bump::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def start_with; end - - sig { returns(T.nilable(String)) } - def tap; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/create.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/create.rbi index bbfe7510c9c8f..3d94822e23083 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/create.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/create.rbi @@ -64,7 +64,4 @@ class Homebrew::DevCmd::Create::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def set_version; end - - sig { returns(T.nilable(String)) } - def tap; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/dispatch_build_bottle.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/dispatch_build_bottle.rbi index 1b71f8cc0fd8b..3f45ac1ca51ab 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/dispatch_build_bottle.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/dispatch_build_bottle.rbi @@ -26,9 +26,6 @@ class Homebrew::DevCmd::DispatchBuildBottle::Args < Homebrew::CLI::Args sig { returns(T.nilable(T::Array[String])) } def macos; end - sig { returns(T.nilable(String)) } - def tap; end - sig { returns(T.nilable(String)) } def timeout; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi index 747ea49b71de2..0729c85370925 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/livecheck_cmd.rbi @@ -46,7 +46,4 @@ class Homebrew::DevCmd::LivecheckCmd::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def resources?; end - - sig { returns(T.nilable(String)) } - def tap; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_automerge.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_automerge.rbi index d2b63c6ab001d..f16fc3dbeeda6 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_automerge.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_automerge.rbi @@ -20,9 +20,6 @@ class Homebrew::DevCmd::PrAutomerge::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def publish?; end - sig { returns(T.nilable(String)) } - def tap; end - sig { returns(T.nilable(String)) } def with_label; end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_publish.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_publish.rbi index c1eff16f78afc..820496cff5573 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_publish.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_publish.rbi @@ -23,9 +23,6 @@ class Homebrew::DevCmd::PrPublish::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def message; end - sig { returns(T.nilable(String)) } - def tap; end - sig { returns(T.nilable(String)) } def workflow; end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_pull.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_pull.rbi index 8a8ac7add7222..ec30c08923d9f 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_pull.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/pr_pull.rbi @@ -65,9 +65,6 @@ class Homebrew::DevCmd::PrPull::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def root_url_using; end - sig { returns(T.nilable(String)) } - def tap; end - sig { returns(T::Boolean) } def warn_on_upload_failure?; end diff --git a/Library/Homebrew/sorbet/tapioca/compilers/args.rb b/Library/Homebrew/sorbet/tapioca/compilers/args.rb index b3ad828b483d2..bf3ee2e77ec1c 100644 --- a/Library/Homebrew/sorbet/tapioca/compilers/args.rb +++ b/Library/Homebrew/sorbet/tapioca/compilers/args.rb @@ -39,11 +39,8 @@ def decorate end end - sig { params(parser: Homebrew::CLI::Parser).returns(T::Hash[Symbol, T.untyped]) } - def args_table(parser) - # we exclude non-args from the table, such as :named and :remaining - parser.instance_variable_get(:@args).instance_variable_get(:@table).except(:named, :remaining) - end + sig { params(parser: Homebrew::CLI::Parser).returns(T::Array[Symbol]) } + def args_table(parser) = parser.args.methods(false) sig { params(parser: Homebrew::CLI::Parser).returns(T::Array[Symbol]) } def comma_arrays(parser) @@ -51,11 +48,11 @@ def comma_arrays(parser) .filter_map { |k, v| parser.option_to_name(k).to_sym if v == :comma_array } end - sig { params(method_name: Symbol, value: T.untyped, comma_array_methods: T::Array[Symbol]).returns(String) } - def get_return_type(method_name, value, comma_array_methods) + sig { params(method_name: Symbol, comma_array_methods: T::Array[Symbol]).returns(String) } + def get_return_type(method_name, comma_array_methods) if comma_array_methods.include?(method_name) "T.nilable(T::Array[String])" - elsif [true, false].include?(value) + elsif method_name.end_with?("?") "T::Boolean" else "T.nilable(String)" @@ -67,11 +64,11 @@ def get_return_type(method_name, value, comma_array_methods) sig { params(klass: RBI::Scope, parser: Homebrew::CLI::Parser).void } def create_args_methods(klass, parser) comma_array_methods = comma_arrays(parser) - args_table(parser).each do |method_name, value| + args_table(parser).each do |method_name| method_name_str = method_name.to_s next if GLOBAL_OPTIONS.include?(method_name_str) - return_type = get_return_type(method_name, value, comma_array_methods) + return_type = get_return_type(method_name, comma_array_methods) klass.create_method(method_name_str, return_type:) end end diff --git a/Library/Homebrew/test/abstract_command_spec.rb b/Library/Homebrew/test/abstract_command_spec.rb index c6669c842b5da..3c24bb6b83c16 100644 --- a/Library/Homebrew/test/abstract_command_spec.rb +++ b/Library/Homebrew/test/abstract_command_spec.rb @@ -22,7 +22,7 @@ def run; end end it "allows access to args" do - expect(TestCat.new(["--bar", "baz"]).args[:bar]).to eq("baz") + expect(TestCat.new(["--bar", "baz"]).args.bar).to eq("baz") end it "raises on invalid args" do diff --git a/Library/Homebrew/test/cask/upgrade_spec.rb b/Library/Homebrew/test/cask/upgrade_spec.rb index 3b5455fcc4485..d2bf61b2b9c0d 100644 --- a/Library/Homebrew/test/cask/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/upgrade_spec.rb @@ -19,7 +19,11 @@ let(:renamed_app) { Cask::CaskLoader.load("renamed-app") } let(:renamed_app_old_path) { renamed_app.config.appdir.join("OldApp.app") } let(:renamed_app_new_path) { renamed_app.config.appdir.join("NewApp.app") } - let(:args) { Homebrew::CLI::Args.new } + let(:args) do + parser = Homebrew::CLI::Parser.new(Homebrew::Cmd::Brew) + parser.cask_options + parser.args + end before do installed.each do |cask| diff --git a/Library/Homebrew/test/sorbet/tapioca/compilers/args_spec.rb b/Library/Homebrew/test/sorbet/tapioca/compilers/args_spec.rb index ee50a912a1950..7761721b292e5 100644 --- a/Library/Homebrew/test/sorbet/tapioca/compilers/args_spec.rb +++ b/Library/Homebrew/test/sorbet/tapioca/compilers/args_spec.rb @@ -18,36 +18,19 @@ describe "#args_table" do it "returns a mapping of list args to default values" do - expect(compiler.args_table(list_parser).keys).to contain_exactly( - :"1?", :built_from_source?, :cask?, :casks?, :d?, :debug?, - :formula?, :formulae?, :full_name?, :h?, :help?, - :installed_as_dependency?, :installed_on_request?, :l?, - :multiple?, :pinned?, :poured_from_bottle?, :q?, :quiet?, - :r?, :t?, :v?, :verbose?, :versions? + expect(compiler.args_table(list_parser)).to contain_exactly( + :"1?", :built_from_source?, :cask?, :casks?, :d?, :debug?, :formula?, :formulae?, :full_name?, :h?, :help?, + :installed_as_dependency?, :installed_on_request?, :l?, :multiple?, :pinned?, :poured_from_bottle?, :q?, + :quiet?, :r?, :t?, :v?, :verbose?, :versions? ) end it "returns a mapping of update-python-resources args to default values" do - expect(compiler.args_table(update_python_resources_parser)).to eq({ - d?: false, - debug?: false, - exclude_packages: nil, - extra_packages: nil, - h?: false, - help?: false, - ignore_non_pypi_packages?: false, - install_dependencies?: false, - p?: false, - package_name: nil, - print_only?: false, - q?: false, - quiet?: false, - s?: false, - silent?: false, - v?: false, - verbose?: false, - version: nil, - }) + expect(compiler.args_table(update_python_resources_parser)).to contain_exactly( + :d?, :debug?, :exclude_packages, :extra_packages, :h?, :help?, :ignore_non_pypi_packages?, + :install_dependencies?, :p?, :package_name, :print_only?, :q?, :quiet?, :s?, :silent?, :v?, :verbose?, + :version + ) end end @@ -65,15 +48,15 @@ let(:comma_arrays) { compiler.comma_arrays(update_python_resources_parser) } it "returns the correct type for switches" do - expect(compiler.get_return_type(:silent?, false, comma_arrays)).to eq("T::Boolean") + expect(compiler.get_return_type(:silent?, comma_arrays)).to eq("T::Boolean") end it "returns the correct type for flags" do - expect(compiler.get_return_type(:package_name, nil, comma_arrays)).to eq("T.nilable(String)") + expect(compiler.get_return_type(:package_name, comma_arrays)).to eq("T.nilable(String)") end it "returns the correct type for comma_arrays" do - expect(compiler.get_return_type(:extra_packages, nil, comma_arrays)).to eq("T.nilable(T::Array[String])") + expect(compiler.get_return_type(:extra_packages, comma_arrays)).to eq("T.nilable(T::Array[String])") end end end