Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
41.44k stars 9.75k forks source link

brew install --cask: search casks if not found #14183

Closed jrmann100 closed 1 year ago

jrmann100 commented 1 year ago

brew doctor output

Your system is ready to brew.

Verification

brew config output

HOMEBREW_VERSION: 3.6.12-20-g9c88c39
ORIGIN: https://github.com/Homebrew/brew
HEAD: 9c88c39baead6bbc40b12ab1eae9b63bcb5a8042
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 9f38328ae25b296117d2d0d19445f8a442d647a1
Core tap last commit: 9 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.0 build 1400
Git: 2.38.1 => /opt/homebrew/bin/git
Curl: 7.84.0 => /usr/bin/curl
macOS: 13.0.1-arm64
CLT: 14.1.0.0.1.1666437224
Xcode: 14.1
Rosetta 2: false

What were you trying to do (and why)?

What were you trying to do: Install a cask with the wrong name.

Why were you trying to do it: Sometimes I mistype the name of a cask, or am fairly confident in guessing the name of the cask. Usually I concurrently run a brew search while I am typing out the install command, but this feels redundant, as the failsafe search feature is already available for formulas and appears to have once been available for casks (#3829).

Why are you opening this issue:

I am opening this issue at the recommendation of @SMillerDev, from Homebrew/discussions/3986.

This issue looks similar to #3829 (please reference this issue if my explanation is unclear), but the fix implemented there does not appear to have lasted through 2022.

What happened (include all command output)?

$ brew install --cask microsoft-edg
Error: Cask 'microsoft-edg' is unavailable: No Cask with this name exists.

What did you expect to happen?

I expected Brew to search for "similarly named formula" or offer a "did you mean" suggestion, as it does with formulas. Here I am omitting the --cask argument to brew install so as to demonstrate how this works with formulas:

$ brew install microsoft-edg
Warning: No available formula with the name "microsoft-edg". Did you mean microsocks?
==> Searching for similarly named formulae...
This similarly named formula was found:
microsocks
To install it, run:
  brew install microsocks
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

Step-by-step reproduction instructions (by running brew commands)

brew install --cask microsoft-edg
brew install --cask google-chroome
apainintheneck commented 1 year ago

~Currently, "did you mean" style suggestions are only implemented for formulae.~ We do have the ability to query Github's API though and I think that was what was added in the PR you mentioned above (not sure when it was removed though). You can see how that looks by trying out brew search.

$ brew search --cask microsoft-edg
==> Casks
microsoft-edge           microsoft-excel          microsoft-teams          microsoft-word

IMO, we could probably just show a modified version of the brew search results if we fail to find a cask/formula to install. We're already kind of doing this anyway.

https://github.com/Homebrew/brew/blob/9c88c39baead6bbc40b12ab1eae9b63bcb5a8042/Library/Homebrew/cmd/install.rb#L281-L324

This is what happens when we fail to find a formula to install. I don't believe that we're actually catching any cask related errors right now in the install command (Cask::CaskUnavailableError doesn't descend from FormulaOrCaskUnavailableError).

https://github.com/Homebrew/brew/blob/9c88c39baead6bbc40b12ab1eae9b63bcb5a8042/Library/Homebrew/cmd/search.rb#L132-L170

This is the logic for finding formula/casks in the search command. It's very similar but it also includes casks which is what you want.

It wouldn't be too hard to move #search_names from cmd/search.rb to search.rb and then use it in the install command but there might be some other reason why we didn't do that originally.

apainintheneck commented 1 year ago

I just took a second look at the search implementation for casks and it does implement the "did you mean" functionality.

MikeMcQuaid commented 1 year ago

IMO, we could probably just show a modified version of the brew search results if we fail to find a cask/formula to install. We're already kind of doing this anyway.

Seems like a good idea 👍🏻