From 307724d5cdf6a6d989eab327827e1f47cd2dc05e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 29 Nov 2020 22:36:24 +0100 Subject: [PATCH] Fix type error in `cmd/cleanup`. --- Library/Homebrew/cmd/cleanup.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 786c28eee3..2900e3e2da 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: false # frozen_string_literal: true require "cleanup" @@ -37,11 +37,18 @@ module Homebrew def cleanup args = cleanup_args.parse - if args.prune.present? && !Integer(args.prune, exception: false) && args.prune != "all" - raise UsageError, "--prune= expects an integer or 'all'." + days = args.prune.presence&.yield_self do |prune| + case prune + when /\A\d+\Z/ + prune.to_i + when "all" + 0 + else + raise UsageError, "--prune= expects an integer or 'all'." + end end - cleanup = Cleanup.new(*args.named, dry_run: args.dry_run?, scrub: args.s?, days: args.prune&.to_i) + cleanup = Cleanup.new(*args.named, dry_run: args.dry_run?, scrub: args.s?, days: days) if args.prune_prefix? cleanup.prune_prefix_symlinks_and_directories return