diff --git a/Library/Homebrew/cask/info.rb b/Library/Homebrew/cask/info.rb index 18ccf66894881..ea38b24222df0 100644 --- a/Library/Homebrew/cask/info.rb +++ b/Library/Homebrew/cask/info.rb @@ -12,7 +12,7 @@ def self.get_info(cask) output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage deprecate_disable = DeprecateDisable.message(cask) output << "#{deprecate_disable.capitalize}\n" if deprecate_disable - output << installation_info(cask) + output << "#{installation_info(cask)}\n" repo = repo_info(cask) output << "#{repo}\n" if repo output << name_info(cask) @@ -37,7 +37,7 @@ def self.title_info(cask) end def self.installation_info(cask) - return "Not installed\n" unless cask.installed? + return "Not installed" unless cask.installed? versioned_staged_path = cask.caskroom_path.join(cask.installed_version) path_details = if versioned_staged_path.exist? @@ -46,7 +46,12 @@ def self.installation_info(cask) Formatter.error("does not exist") end - "Installed\n#{versioned_staged_path} (#{path_details})\n" + tab = Tab.for_cask(cask) + + info = ["Installed"] + info << "#{versioned_staged_path} (#{path_details})" + info << " #{tab}" if tab.tabfile&.exist? + info.join("\n") end def self.name_info(cask) diff --git a/Library/Homebrew/cmd/tab.rb b/Library/Homebrew/cmd/tab.rb index 70b2aa261c8e1..48c891c74ac5e 100644 --- a/Library/Homebrew/cmd/tab.rb +++ b/Library/Homebrew/cmd/tab.rb @@ -10,7 +10,7 @@ module Cmd class TabCmd < AbstractCommand cmd_args do description <<~EOS - Edit tab information for installed formulae. + Edit tab information for installed formulae or casks. This can be useful when you want to control whether an installed formula should be removed by `brew autoremove`. @@ -19,13 +19,18 @@ class TabCmd < AbstractCommand EOS switch "--installed-on-request", - description: "Mark as installed on request." + description: "Mark or as installed on request." switch "--no-installed-on-request", - description: "Mark as not installed on request." + description: "Mark or as not installed on request." + switch "--formula", "--formulae", + description: "Only mark formulae." + switch "--cask", "--casks", + description: "Only mark casks." + conflicts "--formula", "--cask" conflicts "--installed-on-request", "--no-installed-on-request" - named_args :formula, min: 1 + named_args [:installed_formula, :installed_cask], min: 1 end sig { override.void } @@ -37,38 +42,45 @@ def run 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." + formulae, casks = args.named.to_formulae_to_casks + formulae_not_installed = formulae.reject(&:any_version_installed?) + casks_not_installed = casks.reject(&:installed?) + if formulae_not_installed.any? || casks_not_installed.any? + names = formulae_not_installed.map(&:name) + casks_not_installed.map(&:token) + is_or_are = (names.length == 1) ? "is" : "are" + odie "#{names.to_sentence} #{is_or_are} not installed." end - formulae.each do |formula| - update_tab formula, installed_on_request: + [*formulae, *casks].each do |formula_or_cask| + update_tab formula_or_cask, 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? + sig { params(formula_or_cask: T.any(Formula, Cask::Cask), installed_on_request: T::Boolean).void } + def update_tab(formula_or_cask, installed_on_request:) + name, tab = if formula_or_cask.is_a?(Formula) + [formula_or_cask.name, Tab.for_formula(formula_or_cask)] + else + [formula_or_cask.token, formula_or_cask.tab] + end + + if tab.tabfile.blank? || !tab.tabfile.exist? raise ArgumentError, - "Tab file for #{formula.name} does not exist." + "Tab file for #{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}." + ohai "#{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}." + ohai "#{name} is now marked as #{installed_on_request_str}." end end end