Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prune: Use CLI::Parser to parse args #5252

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions Library/Homebrew/cmd/prune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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` [<options>]

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 = []
Expand All @@ -26,7 +44,7 @@ def prune
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
Expand All @@ -46,10 +64,10 @@ def prune
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 "
Expand Down