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

uninstall: Use CLI::Parser to parse args #5300

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
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
27 changes: 23 additions & 4 deletions Library/Homebrew/cmd/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,33 @@
require "formula"
require "diagnostic"
require "migrator"
require "cli_parser"

module Homebrew
module_function

def uninstall_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`uninstall`, `rm`, `remove` [<options>] <formula>

Uninstall <formula>.
EOS
switch :force,
description: "Delete all installed versions of the <formula>"
switch "--ignore-dependencies",
description: "Dont fail uninstall, even if <formula> is a dependency of any installed "\
"formulae."
switch :debug
end
end

def uninstall
raise KegUnspecifiedError if ARGV.named.empty?
uninstall_args.parse

raise KegUnspecifiedError if args.remaining.empty?

kegs_by_rack = if ARGV.force?
kegs_by_rack = if args.force?
Hash[ARGV.named.map do |name|
rack = Formulary.to_rack(name)
next unless rack.directory?
Expand All @@ -33,7 +52,7 @@ def uninstall
return if Homebrew.failed?

kegs_by_rack.each do |rack, kegs|
if ARGV.force?
if args.force?
name = rack.basename

if rack.directory?
Expand Down Expand Up @@ -87,7 +106,7 @@ def uninstall
end

def handle_unsatisfied_dependents(kegs_by_rack)
return if ARGV.include?("--ignore-dependencies")
return if args.ignore_dependencies?

all_kegs = kegs_by_rack.values.flatten(1)
check_for_dependents all_kegs
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cmd/uninstall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
end

specify "when not developer and --ignore-dependencies is specified" do
ARGV << "--ignore-dependencies"
expect(described_class.args).to receive(:ignore_dependencies?).and_return(true)

expect {
described_class.handle_unsatisfied_dependents(opts)
Expand Down