Add brew install --as-dependency

This option avoids needing to immediately use
`brew tab --no-installed-on-request` when manually installing a
dependency.
This commit is contained in:
Mike McQuaid 2025-03-21 15:49:22 +00:00
parent 7ddc4b0196
commit e41a1f6d8a
No known key found for this signature in database
8 changed files with 28 additions and 5 deletions

View File

@ -104,6 +104,9 @@ module Homebrew
[:switch, "--skip-link", { [:switch, "--skip-link", {
description: "Install but skip linking the keg into the prefix.", description: "Install but skip linking the keg into the prefix.",
}], }],
[:switch, "--as-dependency", {
description: "Install but mark as installed as a dependency and not installed on request.",
}],
[:flag, "--bottle-arch=", { [:flag, "--bottle-arch=", {
depends_on: "--build-bottle", depends_on: "--build-bottle",
description: "Optimise bottles for the specified architecture rather than the oldest " \ description: "Optimise bottles for the specified architecture rather than the oldest " \
@ -311,6 +314,8 @@ module Homebrew
Install.install_formulae( Install.install_formulae(
installed_formulae, installed_formulae,
installed_on_request: !args.as_dependency?,
installed_as_dependency: args.as_dependency?,
build_bottle: args.build_bottle?, build_bottle: args.build_bottle?,
force_bottle: args.force_bottle?, force_bottle: args.force_bottle?,
bottle_arch: args.bottle_arch, bottle_arch: args.bottle_arch,
@ -336,7 +341,7 @@ module Homebrew
Upgrade.check_installed_dependents( Upgrade.check_installed_dependents(
installed_formulae, installed_formulae,
flags: args.flags_only, flags: args.flags_only,
installed_on_request: args.named.present?, installed_on_request: !args.as_dependency?,
force_bottle: args.force_bottle?, force_bottle: args.force_bottle?,
build_from_source_formulae: args.build_from_source_formulae, build_from_source_formulae: args.build_from_source_formulae,
interactive: args.interactive?, interactive: args.interactive?,

View File

@ -233,6 +233,8 @@ module Homebrew
def install_formulae( def install_formulae(
formulae_to_install, formulae_to_install,
installed_on_request: true,
installed_as_dependency: false,
build_bottle: false, build_bottle: false,
force_bottle: false, force_bottle: false,
bottle_arch: nil, bottle_arch: nil,
@ -261,8 +263,8 @@ module Homebrew
formula_installer = FormulaInstaller.new( formula_installer = FormulaInstaller.new(
formula, formula,
options: build_options.used_options, options: build_options.used_options,
installed_on_request: true, installed_on_request:,
installed_as_dependency: false, installed_as_dependency:,
build_bottle:, build_bottle:,
force_bottle:, force_bottle:,
bottle_arch:, bottle_arch:,

View File

@ -20,6 +20,9 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
def appdir; end def appdir; end
sig { returns(T::Boolean) }
def as_dependency?; end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def ask?; end def ask?; end

View File

@ -1402,6 +1402,7 @@ _brew_instal() {
--HEAD --HEAD
--adopt --adopt
--appdir --appdir
--as-dependency
--ask --ask
--audio-unit-plugindir --audio-unit-plugindir
--binaries --binaries
@ -1467,6 +1468,7 @@ _brew_install() {
--HEAD --HEAD
--adopt --adopt
--appdir --appdir
--as-dependency
--ask --ask
--audio-unit-plugindir --audio-unit-plugindir
--binaries --binaries

View File

@ -944,6 +944,7 @@ __fish_brew_complete_arg 'info; and not __fish_seen_argument -l formula -l formu
__fish_brew_complete_arg 'instal' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master' __fish_brew_complete_arg 'instal' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master'
__fish_brew_complete_arg 'instal' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`' __fish_brew_complete_arg 'instal' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`'
__fish_brew_complete_arg 'instal' -l appdir -d 'Target location for Applications (default: `/Applications`)' __fish_brew_complete_arg 'instal' -l appdir -d 'Target location for Applications (default: `/Applications`)'
__fish_brew_complete_arg 'instal' -l as-dependency -d 'Install but mark as installed as a dependency and not installed on request'
__fish_brew_complete_arg 'instal' -l ask -d 'Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size' __fish_brew_complete_arg 'instal' -l ask -d 'Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size'
__fish_brew_complete_arg 'instal' -l audio-unit-plugindir -d 'Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)' __fish_brew_complete_arg 'instal' -l audio-unit-plugindir -d 'Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)'
__fish_brew_complete_arg 'instal' -l binaries -d 'Disable/enable linking of helper executables (default: enabled)' __fish_brew_complete_arg 'instal' -l binaries -d 'Disable/enable linking of helper executables (default: enabled)'
@ -1000,6 +1001,7 @@ __fish_brew_complete_cmd 'install' 'Install a formula or cask'
__fish_brew_complete_arg 'install' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master' __fish_brew_complete_arg 'install' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master'
__fish_brew_complete_arg 'install' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`' __fish_brew_complete_arg 'install' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`'
__fish_brew_complete_arg 'install' -l appdir -d 'Target location for Applications (default: `/Applications`)' __fish_brew_complete_arg 'install' -l appdir -d 'Target location for Applications (default: `/Applications`)'
__fish_brew_complete_arg 'install' -l as-dependency -d 'Install but mark as installed as a dependency and not installed on request'
__fish_brew_complete_arg 'install' -l ask -d 'Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size' __fish_brew_complete_arg 'install' -l ask -d 'Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size'
__fish_brew_complete_arg 'install' -l audio-unit-plugindir -d 'Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)' __fish_brew_complete_arg 'install' -l audio-unit-plugindir -d 'Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)'
__fish_brew_complete_arg 'install' -l binaries -d 'Disable/enable linking of helper executables (default: enabled)' __fish_brew_complete_arg 'install' -l binaries -d 'Disable/enable linking of helper executables (default: enabled)'

View File

@ -1187,6 +1187,7 @@ _brew_instal() {
'(--cask)--HEAD[If formula defines it, install the HEAD version, aka. main, trunk, unstable, master]' \ '(--cask)--HEAD[If formula defines it, install the HEAD version, aka. main, trunk, unstable, master]' \
'(--formula --force)--adopt[Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`]' \ '(--formula --force)--adopt[Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`]' \
'(--formula)--appdir[Target location for Applications (default: `/Applications`)]' \ '(--formula)--appdir[Target location for Applications (default: `/Applications`)]' \
'(--cask)--as-dependency[Install but mark as installed as a dependency and not installed on request]' \
'(--cask)--ask[Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size]' \ '(--cask)--ask[Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size]' \
'(--formula)--audio-unit-plugindir[Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)]' \ '(--formula)--audio-unit-plugindir[Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)]' \
'(--formula)--binaries[Disable/enable linking of helper executables (default: enabled)]' \ '(--formula)--binaries[Disable/enable linking of helper executables (default: enabled)]' \
@ -1237,7 +1238,7 @@ _brew_instal() {
'(--casks --binaries --require-sha --quarantine --adopt --skip-cask-deps --zap --appdir --keyboard-layoutdir --colorpickerdir --prefpanedir --qlplugindir --mdimporterdir --dictionarydir --fontdir --servicedir --input-methoddir --internet-plugindir --audio-unit-plugindir --vst-plugindir --vst3-plugindir --screen-saverdir --language)--formula[Treat all named arguments as formulae]' \ '(--casks --binaries --require-sha --quarantine --adopt --skip-cask-deps --zap --appdir --keyboard-layoutdir --colorpickerdir --prefpanedir --qlplugindir --mdimporterdir --dictionarydir --fontdir --servicedir --input-methoddir --internet-plugindir --audio-unit-plugindir --vst-plugindir --vst3-plugindir --screen-saverdir --language)--formula[Treat all named arguments as formulae]' \
'*::formula:__brew_formulae' \ '*::formula:__brew_formulae' \
- cask \ - cask \
'(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \ '(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --as-dependency --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \
'*::cask:__brew_casks' '*::cask:__brew_casks'
} }
@ -1247,6 +1248,7 @@ _brew_install() {
'(--cask)--HEAD[If formula defines it, install the HEAD version, aka. main, trunk, unstable, master]' \ '(--cask)--HEAD[If formula defines it, install the HEAD version, aka. main, trunk, unstable, master]' \
'(--formula --force)--adopt[Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`]' \ '(--formula --force)--adopt[Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`]' \
'(--formula)--appdir[Target location for Applications (default: `/Applications`)]' \ '(--formula)--appdir[Target location for Applications (default: `/Applications`)]' \
'(--cask)--as-dependency[Install but mark as installed as a dependency and not installed on request]' \
'(--cask)--ask[Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size]' \ '(--cask)--ask[Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size]' \
'(--formula)--audio-unit-plugindir[Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)]' \ '(--formula)--audio-unit-plugindir[Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)]' \
'(--formula)--binaries[Disable/enable linking of helper executables (default: enabled)]' \ '(--formula)--binaries[Disable/enable linking of helper executables (default: enabled)]' \
@ -1297,7 +1299,7 @@ _brew_install() {
'(--casks --binaries --require-sha --quarantine --adopt --skip-cask-deps --zap --appdir --keyboard-layoutdir --colorpickerdir --prefpanedir --qlplugindir --mdimporterdir --dictionarydir --fontdir --servicedir --input-methoddir --internet-plugindir --audio-unit-plugindir --vst-plugindir --vst3-plugindir --screen-saverdir --language)--formula[Treat all named arguments as formulae]' \ '(--casks --binaries --require-sha --quarantine --adopt --skip-cask-deps --zap --appdir --keyboard-layoutdir --colorpickerdir --prefpanedir --qlplugindir --mdimporterdir --dictionarydir --fontdir --servicedir --input-methoddir --internet-plugindir --audio-unit-plugindir --vst-plugindir --vst3-plugindir --screen-saverdir --language)--formula[Treat all named arguments as formulae]' \
'*::formula:__brew_formulae' \ '*::formula:__brew_formulae' \
- cask \ - cask \
'(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \ '(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --as-dependency --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \
'*::cask:__brew_casks' '*::cask:__brew_casks'
} }

View File

@ -835,6 +835,10 @@ upgrade *`formula`* if it is already installed but outdated.
: Install but skip linking the keg into the prefix. : Install but skip linking the keg into the prefix.
`--as-dependency`
: Install but mark as installed as a dependency and not installed on request.
`--bottle-arch` `--bottle-arch`
: Optimise bottles for the specified architecture rather than the oldest : Optimise bottles for the specified architecture rather than the oldest

View File

@ -520,6 +520,9 @@ Install but skip any post\-install steps\.
\fB\-\-skip\-link\fP \fB\-\-skip\-link\fP
Install but skip linking the keg into the prefix\. Install but skip linking the keg into the prefix\.
.TP .TP
\fB\-\-as\-dependency\fP
Install but mark as installed as a dependency and not installed on request\.
.TP
\fB\-\-bottle\-arch\fP \fB\-\-bottle\-arch\fP
Optimise bottles for the specified architecture rather than the oldest architecture supported by the version of macOS the bottles are built on\. Optimise bottles for the specified architecture rather than the oldest architecture supported by the version of macOS the bottles are built on\.
.TP .TP