diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb index 5cd689b13b..41cce0329d 100644 --- a/Library/Homebrew/cmd/missing.rb +++ b/Library/Homebrew/cmd/missing.rb @@ -1,48 +1,46 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "formula" require "tab" require "diagnostic" -require "cli/parser" module Homebrew - module_function + module Cmd + class Missing < AbstractCommand + cmd_args do + description <<~EOS + Check the given kegs for missing dependencies. If no are + provided, check all kegs. Will exit with a non-zero status if any kegs are found + to be missing dependencies. + EOS + comma_array "--hide", + description: "Act as if none of the specified are installed. should be " \ + "a comma-separated list of formulae." - sig { returns(CLI::Parser) } - def missing_args - Homebrew::CLI::Parser.new do - description <<~EOS - Check the given kegs for missing dependencies. If no are - provided, check all kegs. Will exit with a non-zero status if any kegs are found - to be missing dependencies. - EOS - comma_array "--hide", - description: "Act as if none of the specified are installed. should be " \ - "a comma-separated list of formulae." + named_args :formula + end - named_args :formula - end - end + sig { override.void } + def run + return unless HOMEBREW_CELLAR.exist? - def missing - args = missing_args.parse + ff = if args.no_named? + Formula.installed.sort + else + args.named.to_resolved_formulae.sort + end - return unless HOMEBREW_CELLAR.exist? + ff.each do |f| + missing = f.missing_dependencies(hide: args.hide) + next if missing.empty? - ff = if args.no_named? - Formula.installed.sort - else - args.named.to_resolved_formulae.sort - end - - ff.each do |f| - missing = f.missing_dependencies(hide: args.hide) - next if missing.empty? - - Homebrew.failed = true - print "#{f}: " if ff.size > 1 - puts missing.join(" ") + Homebrew.failed = true + print "#{f}: " if ff.size > 1 + puts missing.join(" ") + end + end end end end diff --git a/Library/Homebrew/test/cmd/missing_spec.rb b/Library/Homebrew/test/cmd/missing_spec.rb index 0e9043bdce..d1cbb37d8b 100644 --- a/Library/Homebrew/test/cmd/missing_spec.rb +++ b/Library/Homebrew/test/cmd/missing_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +require "cmd/missing" require "cmd/shared_examples/args_parse" -RSpec.describe "brew missing" do +RSpec.describe Homebrew::Cmd::Missing do it_behaves_like "parseable arguments" it "prints missing dependencies", :integration_test do