-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `brew tab`, a new command to edit tab information, as previously discussed in #17125 (comment). Currently, this supports marking or unmarking formulae as installed on request. Sample usage: $ brew tab --installed-on-request curl ==> curl is now marked as installed on request. $ brew autoremove --dry-run [no output] $ brew tab --no-installed-on-request curl ==> curl is now marked as not installed on request. $ brew autoremove --dry-run ==> Would autoremove 2 unneeded formulae: curl rtmpdump Co-authored-by: Mike McQuaid <[email protected]>
- Loading branch information
1 parent
c997fa5
commit 3e034da
Showing
10 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require "abstract_command" | ||
require "formula" | ||
require "tab" | ||
|
||
module Homebrew | ||
module Cmd | ||
class Tab < AbstractCommand | ||
cmd_args do | ||
description <<~EOS | ||
Edit tab information for installed formulae. | ||
This can be useful when you want to control whether an installed | ||
formula should be removed by `brew autoremove`. | ||
To prevent removal, mark the formula as installed on request; | ||
to allow removal, mark the formula as not installed on request. | ||
EOS | ||
|
||
switch "--installed-on-request", | ||
description: "Mark <formula> as installed on request." | ||
switch "--no-installed-on-request", | ||
description: "Mark <formula> as not installed on request." | ||
|
||
conflicts "--installed-on-request", "--no-installed-on-request" | ||
|
||
named_args :formula, min: 1 | ||
end | ||
|
||
sig { override.void } | ||
def run | ||
installed_on_request = if args.installed_on_request? | ||
true | ||
elsif args.no_installed_on_request? | ||
false | ||
end | ||
raise UsageError, "No marking option specified." if installed_on_request.nil? | ||
|
||
formulae = args.named.to_formulae | ||
if (formulae_not_installed = formulae.reject(&:any_version_installed?)).any? | ||
formula_names = formulae_not_installed.map(&:name) | ||
is_or_are = (formula_names.length == 1) ? "is" : "are" | ||
odie "#{formula_names.to_sentence} #{is_or_are} not installed." | ||
end | ||
|
||
formulae.each do |formula| | ||
update_tab formula, installed_on_request: | ||
end | ||
end | ||
|
||
private | ||
|
||
sig { params(formula: Formula, installed_on_request: T::Boolean).void } | ||
def update_tab(formula, installed_on_request:) | ||
tab = ::Tab.for_formula(formula) | ||
unless tab.tabfile.exist? | ||
raise ArgumentError, | ||
"Tab file for #{formula.name} does not exist." | ||
end | ||
|
||
installed_on_request_str = "#{"not " unless installed_on_request}installed on request" | ||
if (tab.installed_on_request && installed_on_request) || | ||
(!tab.installed_on_request && !installed_on_request) | ||
ohai "#{formula.name} is already marked as #{installed_on_request_str}." | ||
return | ||
end | ||
|
||
tab.installed_on_request = installed_on_request | ||
tab.write | ||
ohai "#{formula.name} is now marked as #{installed_on_request_str}." | ||
end | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cmd/tab" | ||
require "cmd/shared_examples/args_parse" | ||
require "tab" | ||
|
||
RSpec.describe Homebrew::Cmd::Tab do | ||
def installed_on_request?(formula) | ||
# `brew` subprocesses can change the tab, invalidating the cached values. | ||
Tab.clear_cache | ||
Tab.for_formula(formula).installed_on_request | ||
end | ||
|
||
it_behaves_like "parseable arguments" | ||
|
||
it "marks or unmarks a formula as installed on request", :integration_test do | ||
setup_test_formula "foo", | ||
tab_attributes: { "installed_on_request" => false } | ||
foo = Formula["foo"] | ||
|
||
expect { brew "tab", "--installed-on-request", "foo" } | ||
.to be_a_success | ||
.and output(/foo is now marked as installed on request/).to_stdout | ||
.and not_to_output.to_stderr | ||
expect(installed_on_request?(foo)).to be true | ||
|
||
expect { brew "tab", "--no-installed-on-request", "foo" } | ||
.to be_a_success | ||
.and output(/foo is now marked as not installed on request/).to_stdout | ||
.and not_to_output.to_stderr | ||
expect(installed_on_request?(foo)).to be false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ setup-ruby | |
sh | ||
shellenv | ||
style | ||
tab | ||
tap | ||
tap-info | ||
tap-new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters