install: check for --only-dependencies flag earlier

Currently, doing `brew install --only-dependencies` with an unlinked
formula does nothing and returns a message saying the formula is already
installed but just not linked.

I think that we should just install the dependencies as requested here
instead of complaining that the formula isn't linked.

Before:

    ❯ brew unlink adplug
    Unlinking /usr/local/Cellar/adplug/2.3.3... 8 symlinks removed.
    ❯ brew install --only-dependencies adplug
    Warning: adplug 2.3.3 is already installed, it's just not linked.
    To link this version, run:
      brew link adplug

After:

    ❯ brew install --only-dependencies adplug
    ==> Fetching dependencies for adplug: libbinio
    ==> Fetching libbinio
    ==> Downloading https://ghcr.io/v2/homebrew/core/libbinio/manifests/1.5
    [snip]

See Homebrew/homebrew-core#127133 for additional context.
This commit is contained in:
Carlo Cabrera 2023-04-02 01:39:23 +08:00
parent 931327df1f
commit 6c3361e80f
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -174,15 +174,15 @@ module Homebrew
The currently linked version is: #{formula.linked_version}
EOS
end
elsif only_dependencies
msg = nil
return true
elsif !formula.linked? || formula.keg_only?
msg = <<~EOS
#{msg}, it's just not linked.
To link this version, run:
brew link #{formula}
EOS
elsif only_dependencies
msg = nil
return true
else
msg = if quiet
nil