Merge pull request #5300 from GauthamGoli/uninstall-args

uninstall: Use CLI::Parser to parse args
This commit is contained in:
Mike McQuaid 2018-12-11 08:49:22 +00:00 committed by GitHub
commit dbc43a7a2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View File

@ -11,14 +11,33 @@ require "keg"
require "formula" require "formula"
require "diagnostic" require "diagnostic"
require "migrator" require "migrator"
require "cli_parser"
module Homebrew module Homebrew
module_function module_function
def uninstall def uninstall_args
raise KegUnspecifiedError if ARGV.named.empty? Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`uninstall`, `rm`, `remove` [<options>] <formula>
kegs_by_rack = if ARGV.force? 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
uninstall_args.parse
raise KegUnspecifiedError if args.remaining.empty?
kegs_by_rack = if args.force?
Hash[ARGV.named.map do |name| Hash[ARGV.named.map do |name|
rack = Formulary.to_rack(name) rack = Formulary.to_rack(name)
next unless rack.directory? next unless rack.directory?
@ -33,7 +52,7 @@ module Homebrew
return if Homebrew.failed? return if Homebrew.failed?
kegs_by_rack.each do |rack, kegs| kegs_by_rack.each do |rack, kegs|
if ARGV.force? if args.force?
name = rack.basename name = rack.basename
if rack.directory? if rack.directory?
@ -87,7 +106,7 @@ module Homebrew
end end
def handle_unsatisfied_dependents(kegs_by_rack) 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) all_kegs = kegs_by_rack.values.flatten(1)
check_for_dependents all_kegs check_for_dependents all_kegs

View File

@ -60,7 +60,7 @@ describe Homebrew do
end end
specify "when not developer and --ignore-dependencies is specified" do 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 { expect {
described_class.handle_unsatisfied_dependents(opts) described_class.handle_unsatisfied_dependents(opts)