uninstall: Use CLI::Parser to parse args

This commit is contained in:
Gautham Goli 2018-11-11 17:43:31 +05:30
parent 00075c228c
commit f82a202995
No known key found for this signature in database
GPG Key ID: 6A9ABBC284468364
2 changed files with 25 additions and 6 deletions

View File

@ -11,14 +11,33 @@ require "keg"
require "formula"
require "diagnostic"
require "migrator"
require "cli_parser"
module Homebrew
module_function
def uninstall
raise KegUnspecifiedError if ARGV.named.empty?
def uninstall_args
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|
rack = Formulary.to_rack(name)
next unless rack.directory?
@ -33,7 +52,7 @@ module Homebrew
return if Homebrew.failed?
kegs_by_rack.each do |rack, kegs|
if ARGV.force?
if args.force?
name = rack.basename
if rack.directory?
@ -87,7 +106,7 @@ module Homebrew
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

View File

@ -60,7 +60,7 @@ describe Homebrew do
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)