From 8e8e85fc948370b3328aeddaf99abac92e0bf76a Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 5 Nov 2018 17:07:33 +0530 Subject: [PATCH] prune: Use CLI::Parser to parse args --- Library/Homebrew/cmd/prune.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb index e26049e1c6..ba3d768edd 100644 --- a/Library/Homebrew/cmd/prune.rb +++ b/Library/Homebrew/cmd/prune.rb @@ -6,11 +6,29 @@ #: actually remove anything. require "keg" +require "cli_parser" module Homebrew module_function + def prune_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `prune` [] + + Remove dead symlinks from the Homebrew prefix. This is generally not + needed, but can be useful when doing DIY installations. + EOS + switch "-n", "--dry-run", + description: "Show what would be removed, but do not actually remove anything." + switch :verbose + switch :debug + end + end + def prune + prune_args.parse + ObserverPathnameExtension.reset_counts! dirs = [] @@ -26,7 +44,7 @@ module Homebrew path.uninstall_info unless ARGV.dry_run? end - if ARGV.dry_run? + if args.dry_run? puts "Would remove (broken link): #{path}" else path.unlink @@ -46,10 +64,10 @@ module Homebrew end end - return if ARGV.dry_run? + return if args.dry_run? if ObserverPathnameExtension.total.zero? - puts "Nothing pruned" if ARGV.verbose? + puts "Nothing pruned" if args.verbose? else n, d = ObserverPathnameExtension.counts print "Pruned #{n} symbolic links "