cmd: add autoremove command
This commit is contained in:
parent
4127a7b624
commit
0fa417706a
54
Library/Homebrew/cmd/autoremove.rb
Normal file
54
Library/Homebrew/cmd/autoremove.rb
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "formula"
|
||||||
|
require "cli/parser"
|
||||||
|
|
||||||
|
module Homebrew
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def autoremove_args
|
||||||
|
Homebrew::CLI::Parser.new do
|
||||||
|
usage_banner <<~EOS
|
||||||
|
`autoremove` [<options>]
|
||||||
|
|
||||||
|
Remove packages that weren't installed on request and are no longer needed.
|
||||||
|
EOS
|
||||||
|
switch "-n", "--dry-run",
|
||||||
|
description: "Just print what would be removed."
|
||||||
|
named 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_removable_formulae(installed_formulae)
|
||||||
|
removable_formulae = []
|
||||||
|
|
||||||
|
installed_formulae.each do |formula|
|
||||||
|
# Reject formulae installed on request.
|
||||||
|
next if Tab.for_keg(formula.any_installed_keg).installed_on_request
|
||||||
|
# Reject formulae which are needed at runtime by other formulae.
|
||||||
|
next if installed_formulae.flat_map(&:runtime_formula_dependencies).include?(formula)
|
||||||
|
|
||||||
|
removable_formulae << installed_formulae.delete(formula)
|
||||||
|
removable_formulae += get_removable_formulae(installed_formulae)
|
||||||
|
end
|
||||||
|
|
||||||
|
removable_formulae
|
||||||
|
end
|
||||||
|
|
||||||
|
def autoremove
|
||||||
|
args = autoremove_args.parse
|
||||||
|
|
||||||
|
removable_formulae = get_removable_formulae(Formula.installed.sort)
|
||||||
|
|
||||||
|
return if removable_formulae.blank?
|
||||||
|
|
||||||
|
formulae_names = removable_formulae.map(&:full_name)
|
||||||
|
|
||||||
|
oh1 "Formulae that could be removed"
|
||||||
|
puts formulae_names
|
||||||
|
|
||||||
|
return if args.dry_run?
|
||||||
|
|
||||||
|
system HOMEBREW_BREW_FILE, "rm", *formulae_names
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -33,6 +33,7 @@ RSpec/MultipleDescribes:
|
|||||||
- 'cmd/--repository_spec.rb'
|
- 'cmd/--repository_spec.rb'
|
||||||
- 'cmd/--version_spec.rb'
|
- 'cmd/--version_spec.rb'
|
||||||
- 'cmd/analytics_spec.rb'
|
- 'cmd/analytics_spec.rb'
|
||||||
|
- 'cmd/autoremove_spec.rb'
|
||||||
- 'cmd/cleanup_spec.rb'
|
- 'cmd/cleanup_spec.rb'
|
||||||
- 'cmd/commands_spec.rb'
|
- 'cmd/commands_spec.rb'
|
||||||
- 'cmd/config_spec.rb'
|
- 'cmd/config_spec.rb'
|
||||||
|
|||||||
7
Library/Homebrew/test/cmd/autoremove_spec.rb
Normal file
7
Library/Homebrew/test/cmd/autoremove_spec.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cmd/shared_examples/args_parse"
|
||||||
|
|
||||||
|
describe "Homebrew.autoremove_args" do
|
||||||
|
it_behaves_like "parseable arguments"
|
||||||
|
end
|
||||||
@ -12,6 +12,7 @@
|
|||||||
abv
|
abv
|
||||||
analytics
|
analytics
|
||||||
audit
|
audit
|
||||||
|
autoremove
|
||||||
bottle
|
bottle
|
||||||
bump
|
bump
|
||||||
bump-cask-pr
|
bump-cask-pr
|
||||||
|
|||||||
@ -56,6 +56,13 @@ Turn Homebrew's analytics on or off respectively.
|
|||||||
`brew analytics regenerate-uuid`:
|
`brew analytics regenerate-uuid`:
|
||||||
Regenerate the UUID used for Homebrew's analytics.
|
Regenerate the UUID used for Homebrew's analytics.
|
||||||
|
|
||||||
|
### `autoremove` [*`options`*]
|
||||||
|
|
||||||
|
Remove packages that weren't installed on request and are no longer needed.
|
||||||
|
|
||||||
|
* `-n`, `--dry-run`:
|
||||||
|
Just print what would be removed.
|
||||||
|
|
||||||
### `cask` *`command`* [*`options`*] [*`cask`*]
|
### `cask` *`command`* [*`options`*] [*`cask`*]
|
||||||
|
|
||||||
Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries.
|
Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries.
|
||||||
|
|||||||
@ -53,6 +53,13 @@ Control Homebrew\'s anonymous aggregate user behaviour analytics\. Read more at
|
|||||||
\fBbrew analytics regenerate\-uuid\fR
|
\fBbrew analytics regenerate\-uuid\fR
|
||||||
Regenerate the UUID used for Homebrew\'s analytics\.
|
Regenerate the UUID used for Homebrew\'s analytics\.
|
||||||
.
|
.
|
||||||
|
.SS "\fBautoremove\fR [\fIoptions\fR]"
|
||||||
|
Remove packages that weren\'t installed on request and are no longer needed\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
|
\fB\-n\fR, \fB\-\-dry\-run\fR
|
||||||
|
Just print what would be removed\.
|
||||||
|
.
|
||||||
.SS "\fBcask\fR \fIcommand\fR [\fIoptions\fR] [\fIcask\fR]"
|
.SS "\fBcask\fR \fIcommand\fR [\fIoptions\fR] [\fIcask\fR]"
|
||||||
Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries\.
|
Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries\.
|
||||||
.
|
.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user