cmd/uninstall: Add env variable that runs autoremove after uninstalls

When HOMEBREW_UNINSTALL_AUTOREMOVE is set, `brew autoremove` is run
after every successful call to `brew uninstall`.
This commit is contained in:
apainintheneck 2022-07-08 10:21:57 -07:00
parent 40b20dea22
commit f8ae5f3bc4
5 changed files with 24 additions and 0 deletions

View File

@ -50,6 +50,11 @@ module Homebrew
all_kegs: args.force?,
)
# If ignore_unavailable is true and the named args
# are a series of invalid kegs and casks,
# #to_kegs_to_casks will return empty arrays.
return if all_kegs.blank? && casks.blank?
kegs_by_rack = all_kegs.group_by(&:rack)
Uninstall.uninstall_kegs(
@ -73,5 +78,9 @@ module Homebrew
force: args.force?,
)
end
return unless Homebrew::EnvConfig.uninstall_autoremove?
system HOMEBREW_BREW_FILE, "autoremove"
end
end

View File

@ -343,6 +343,10 @@ module Homebrew
default_text: "macOS: `/private/tmp`, Linux: `/tmp`.",
default: HOMEBREW_DEFAULT_TEMP,
},
HOMEBREW_UNINSTALL_AUTOREMOVE: {
description: "If set, `brew autoremove` is run after every successful call to `brew uninstall`.",
boolean: true,
},
HOMEBREW_UPDATE_REPORT_ALL_FORMULAE: {
description: "If set, `brew update` lists changes to all formulae and cask files rather than only showing " \
"when they are new and not installed or outdated and installed.",

View File

@ -2572,6 +2572,8 @@ module Homebrew::EnvConfig
def self.temp(); end
def self.uninstall_autoremove?(); end
def self.update_report_all_formulae?(); end
def self.update_to_tag?(); end

View File

@ -2184,6 +2184,9 @@ example, run `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just
*Default:* macOS: `/private/tmp`, Linux: `/tmp`.
- `HOMEBREW_UNINSTALL_AUTOREMOVE`
<br>If set, `brew autoremove` is run after every successful call to `brew uninstall`.
- `HOMEBREW_UPDATE_REPORT_ALL_FORMULAE`
<br>If set, `brew update` lists changes to all formulae and cask files rather than only showing when they are new and not installed or outdated and installed.

View File

@ -3207,6 +3207,12 @@ Use this path as the temporary directory for building packages\. Changing this m
\fIDefault:\fR macOS: \fB/private/tmp\fR, Linux: \fB/tmp\fR\.
.
.TP
\fBHOMEBREW_UNINSTALL_AUTOREMOVE\fR
.
.br
If set, \fBbrew autoremove\fR is run after every successful call to \fBbrew uninstall\fR\.
.
.TP
\fBHOMEBREW_UPDATE_REPORT_ALL_FORMULAE\fR
.
.br