Support all cask options in brew install.

This commit is contained in:
Markus Reiter 2020-09-27 22:53:01 +02:00
parent d443afc82d
commit 08be729af0
6 changed files with 236 additions and 131 deletions

View File

@ -79,6 +79,70 @@ module Cask
EOS EOS
end end
OPTIONS = [
[:flag, "--appdir=", {
description: "Target location for Applications. " \
"Default: `#{Config::DEFAULT_DIRS[:appdir]}`",
}],
[:flag, "--colorpickerdir=", {
description: "Target location for Color Pickers. " \
"Default: `#{Config::DEFAULT_DIRS[:colorpickerdir]}`",
}],
[:flag, "--prefpanedir=", {
description: "Target location for Preference Panes. " \
"Default: `#{Config::DEFAULT_DIRS[:prefpanedir]}`",
}],
[:flag, "--qlplugindir=", {
description: "Target location for QuickLook Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:qlplugindir]}`",
}],
[:flag, "--mdimporterdir=", {
description: "Target location for Spotlight Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:mdimporterdir]}`",
}],
[:flag, "--dictionarydir=", {
description: "Target location for Dictionaries. " \
"Default: `#{Config::DEFAULT_DIRS[:dictionarydir]}`",
}],
[:flag, "--fontdir=", {
description: "Target location for Fonts. " \
"Default: `#{Config::DEFAULT_DIRS[:fontdir]}`",
}],
[:flag, "--servicedir=", {
description: "Target location for Services. " \
"Default: `#{Config::DEFAULT_DIRS[:servicedir]}`",
}],
[:flag, "--input_methoddir=", {
description: "Target location for Input Methods. " \
"Default: `#{Config::DEFAULT_DIRS[:input_methoddir]}`",
}],
[:flag, "--internet_plugindir=", {
description: "Target location for Internet Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:internet_plugindir]}`",
}],
[:flag, "--audio_unit_plugindir=", {
description: "Target location for Audio Unit Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:audio_unit_plugindir]}`",
}],
[:flag, "--vst_plugindir=", {
description: "Target location for VST Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:vst_plugindir]}`",
}],
[:flag, "--vst3_plugindir=", {
description: "Target location for VST3 Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:vst3_plugindir]}`",
}],
[:flag, "--screen_saverdir=", {
description: "Target location for Screen Savers. " \
"Default: `#{Config::DEFAULT_DIRS[:screen_saverdir]}`",
}],
[:comma_array, "--language", {
description: "Set language of the Cask to install. The first matching " \
"language is used, otherwise the default language on the Cask. " \
"The default value is the `language of your system`",
}],
].freeze
def self.parser(&block) def self.parser(&block)
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
if block_given? if block_given?
@ -91,52 +155,9 @@ module Cask
EOS EOS
end end
flag "--appdir=", OPTIONS.each do |option|
description: "Target location for Applications. " \ send(*option)
"Default: `#{Config::DEFAULT_DIRS[:appdir]}`" end
flag "--colorpickerdir=",
description: "Target location for Color Pickers. " \
"Default: `#{Config::DEFAULT_DIRS[:colorpickerdir]}`"
flag "--prefpanedir=",
description: "Target location for Preference Panes. " \
"Default: `#{Config::DEFAULT_DIRS[:prefpanedir]}`"
flag "--qlplugindir=",
description: "Target location for QuickLook Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:qlplugindir]}`"
flag "--mdimporterdir=",
description: "Target location for Spotlight Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:mdimporterdir]}`"
flag "--dictionarydir=",
description: "Target location for Dictionaries. " \
"Default: `#{Config::DEFAULT_DIRS[:dictionarydir]}`"
flag "--fontdir=",
description: "Target location for Fonts. " \
"Default: `#{Config::DEFAULT_DIRS[:fontdir]}`"
flag "--servicedir=",
description: "Target location for Services. " \
"Default: `#{Config::DEFAULT_DIRS[:servicedir]}`"
flag "--input_methoddir=",
description: "Target location for Input Methods. " \
"Default: `#{Config::DEFAULT_DIRS[:input_methoddir]}`"
flag "--internet_plugindir=",
description: "Target location for Internet Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:internet_plugindir]}`"
flag "--audio_unit_plugindir=",
description: "Target location for Audio Unit Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:audio_unit_plugindir]}`"
flag "--vst_plugindir=",
description: "Target location for VST Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:vst_plugindir]}`"
flag "--vst3_plugindir=",
description: "Target location for VST3 Plugins. " \
"Default: `#{Config::DEFAULT_DIRS[:vst3_plugindir]}`"
flag "--screen_saverdir=",
description: "Target location for Screen Savers. " \
"Default: `#{Config::DEFAULT_DIRS[:screen_saverdir]}`"
comma_array "--language",
description: "Set language of the Cask to install. The first matching " \
"language is used, otherwise the default language on the Cask. " \
"The default value is the `language of your system`"
end end
end end

View File

@ -33,6 +33,22 @@ module Cask
"`#{command_name}` [<options>]#{banner_args}" "`#{command_name}` [<options>]#{banner_args}"
end end
OPTIONS = [
[:switch, "--[no-]binaries", {
description: "Disable/enable linking of helper executables to `#{Config.global.binarydir}`. " \
"Default: enabled",
env: :cask_opts_binaries,
}],
[:switch, "--require-sha", {
description: "Require all casks to have a checksum.",
env: :cask_opts_require_sha,
}],
[:switch, "--[no-]quarantine", {
description: "Disable/enable quarantining of downloads. Default: enabled",
env: :cask_opts_quarantine,
}],
].freeze
def self.parser(&block) def self.parser(&block)
banner = <<~EOS banner = <<~EOS
`cask` #{banner_headline} `cask` #{banner_headline}
@ -48,18 +64,9 @@ module Cask
instance_eval(&block) if block_given? instance_eval(&block) if block_given?
switch "--[no-]binaries", OPTIONS.each do |option|
description: "Disable/enable linking of helper executables to `#{Config.global.binarydir}`. " \ send(*option)
"Default: enabled", end
env: :cask_opts_binaries
switch "--require-sha",
description: "Require all casks to have a checksum.",
env: :cask_opts_require_sha
switch "--[no-]quarantine",
description: "Disable/enable quarantining of downloads. Default: enabled",
env: :cask_opts_quarantine
min_named min_n unless min_n.nil? min_named min_n unless min_n.nil?
max_named max_n unless max_n.nil? max_named max_n unless max_n.nil?

View File

@ -14,12 +14,20 @@ module Cask
"Installs the given <cask>." "Installs the given <cask>."
end end
OPTIONS = [
[:switch, "--skip-cask-deps", {
description: "Skip installing cask dependencies.",
}],
].freeze
def self.parser(&block) def self.parser(&block)
super do super do
switch "--force", switch "--force",
description: "Force overwriting existing files." description: "Force overwriting existing files."
switch "--skip-cask-deps",
description: "Skip installing cask dependencies." OPTIONS.each do |option|
send(*option)
end
instance_eval(&block) if block_given? instance_eval(&block) if block_given?
end end

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cask/config" require "cask/config"
require "cask/cmd"
require "cask/cmd/install"
require "missing_formula" require "missing_formula"
require "formula_installer" require "formula_installer"
require "development_tools" require "development_tools"
@ -16,50 +18,37 @@ module Homebrew
module_function module_function
def install_args def install_args
cask_only_options = { cask_only_options = [
["--cask", "--casks"] => { [:switch, "--cask", "--casks", {
description: "Treat all named arguments as casks.", description: "Treat all named arguments as casks.",
}, }],
["--[no-]binaries"] => { *Cask::Cmd::OPTIONS,
description: "Disable/enable linking of helper executables to `#{Cask::Config.global.binarydir}`. " \ *Cask::Cmd::AbstractCommand::OPTIONS,
"Default: enabled", *Cask::Cmd::Install::OPTIONS,
env: :cask_opts_binaries, ]
},
["--require-sha"] => {
description: "Require all casks to have a checksum.",
env: :cask_opts_require_sha,
},
["--[no-]quarantine"] => {
description: "Disable/enable quarantining of downloads. Default: enabled",
env: :cask_opts_quarantine,
},
["--skip-cask-deps"] => {
description: "Skip installing cask dependencies.",
},
}.freeze
formula_only_options = { formula_only_options = [
["--formula", "--formulae"] => { [:switch, "--formula", "--formulae", {
description: "Treat all named arguments as formulae.", description: "Treat all named arguments as formulae.",
}, }],
["--env="] => { [:flag, "--env=", {
description: "If `std` is passed, use the standard build environment instead of superenv. "\ description: "If `std` is passed, use the standard build environment instead of superenv. "\
"If `super` is passed, use superenv even if the formula specifies the "\ "If `super` is passed, use superenv even if the formula specifies the "\
"standard build environment.", "standard build environment.",
}, }],
["--ignore-dependencies"] => { [:switch, "--ignore-dependencies", {
description: "An unsupported Homebrew development flag to skip installing any dependencies of "\ description: "An unsupported Homebrew development flag to skip installing any dependencies of "\
"any kind. If the dependencies are not already present, the formula will have issues. "\ "any kind. If the dependencies are not already present, the formula will have issues. "\
"If you're not developing Homebrew, consider adjusting your PATH rather than "\ "If you're not developing Homebrew, consider adjusting your PATH rather than "\
"using this flag.", "using this flag.",
}, }],
["--only-dependencies"] => { [:switch, "--only-dependencies", {
description: "Install the dependencies with specified options but do not install the "\ description: "Install the dependencies with specified options but do not install the "\
"formula itself.", "formula itself.",
}, }],
["--cc="] => { [:flag, "--cc=", {
description: "Attempt to compile using the specified <compiler>, which should be the "\ description: "Attempt to compile using the specified <compiler>, which should be the "\
"name of the compiler's executable, e.g. `gcc-7` for GCC 7. "\ "name of the compiler's executable, e.g. `gcc-7` for GCC 7. "\
"In order to use LLVM's clang, specify `llvm_clang`. To use the "\ "In order to use LLVM's clang, specify `llvm_clang`. To use the "\
@ -67,59 +56,56 @@ module Homebrew
"compilers that are provided by Homebrew or bundled with macOS. "\ "compilers that are provided by Homebrew or bundled with macOS. "\
"Please do not file issues if you encounter errors while using this option.", "Please do not file issues if you encounter errors while using this option.",
}, }],
["-s", "--build-from-source"] => { [:switch, "-s", "--build-from-source", {
description: "Compile <formula> from source even if a bottle is provided. "\ description: "Compile <formula> from source even if a bottle is provided. "\
"Dependencies will still be installed from bottles if they are available.", "Dependencies will still be installed from bottles if they are available.",
}, }],
["--force-bottle"] => { [:switch, "--force-bottle", {
description: "Install from a bottle if it exists for the current or newest version of "\ description: "Install from a bottle if it exists for the current or newest version of "\
"macOS, even if it would not normally be used for installation.", "macOS, even if it would not normally be used for installation.",
}, }],
["--include-test"] => { [:switch, "--include-test", {
description: "Install testing dependencies required to run `brew test` <formula>.", description: "Install testing dependencies required to run `brew test` <formula>.",
}, }],
["--HEAD"] => { [:switch, "--HEAD", {
description: "If <formula> defines it, install the HEAD version, aka. master, trunk, unstable.", description: "If <formula> defines it, install the HEAD version, aka. master, trunk, unstable.",
}, }], [:switch, "--fetch-HEAD", {
["--fetch-HEAD"] => {
description: "Fetch the upstream repository to detect if the HEAD installation of the "\ description: "Fetch the upstream repository to detect if the HEAD installation of the "\
"formula is outdated. Otherwise, the repository's HEAD will only be checked for "\ "formula is outdated. Otherwise, the repository's HEAD will only be checked for "\
"updates when a new stable or development version has been released.", "updates when a new stable or development version has been released.",
}, }], [:switch, "--keep-tmp", {
["--keep-tmp"] => {
description: "Retain the temporary files created during installation.", description: "Retain the temporary files created during installation.",
}, }], [:switch, "--build-bottle", {
["--build-bottle"] => {
description: "Prepare the formula for eventual bottling during installation, skipping any "\ description: "Prepare the formula for eventual bottling during installation, skipping any "\
"post-install steps.", "post-install steps.",
}, }],
["--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 "\
"architecture supported by the version of macOS the bottles are built on.", "architecture supported by the version of macOS the bottles are built on.",
}, }],
["--display-times"] => { [:switch, "--display-times", {
env: :display_install_times, env: :display_install_times,
description: "Print install times for each formula at the end of the run.", description: "Print install times for each formula at the end of the run.",
}, }],
["-i", "--interactive"] => { [:switch, "-i", "--interactive", {
description: "Download and patch <formula>, then open a shell. This allows the user to "\ description: "Download and patch <formula>, then open a shell. This allows the user to "\
"run `./configure --help` and otherwise determine how to turn the software "\ "run `./configure --help` and otherwise determine how to turn the software "\
"package into a Homebrew package.", "package into a Homebrew package.",
}, }],
["-g", "--git"] => { [:switch, "-g", "--git", {
description: "Create a Git repository, useful for creating patches to the software.", description: "Create a Git repository, useful for creating patches to the software.",
}, }]
}.freeze ]
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
@ -134,27 +120,22 @@ module Homebrew
description: "If brewing fails, open an interactive debugging session with access to IRB "\ description: "If brewing fails, open an interactive debugging session with access to IRB "\
"or a shell inside the temporary build directory." "or a shell inside the temporary build directory."
switch "-f", "--force", switch "-f", "--force",
description: "Install without checking for previously installed keg-only or "\ description: "Install formulae without checking for previously installed keg-only or "\
"non-migrated versions." "non-migrated versions. Overwrite existing files when installing casks."
switch "-v", "--verbose", switch "-v", "--verbose",
description: "Print the verification and postinstall steps." description: "Print the verification and postinstall steps."
conflicts "--ignore-dependencies", "--only-dependencies" conflicts "--ignore-dependencies", "--only-dependencies"
conflicts "--build-from-source", "--build-bottle", "--force-bottle" conflicts "--build-from-source", "--build-bottle", "--force-bottle"
formula_only_options.each do |flags, **options| formula_only_options.each do |options|
if flags.last.end_with?("=") send(*options)
flag(*flags, **options) conflicts "--cask", options[-2]
else
switch(*flags, **options)
end end
conflicts "--cask", flags.last cask_only_options.each do |options|
end send(*options)
conflicts "--formula", options[-2]
cask_only_options.each do |flags, **options|
switch(*flags, **options)
conflicts "--formula", flags.last
end end
formula_options formula_options
@ -187,8 +168,6 @@ module Homebrew
formulae, casks = formulae_or_casks.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) } formulae, casks = formulae_or_casks.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) }
if casks.any? if casks.any?
require "cask/cmd/install"
Cask::Cmd::Install.install_casks( Cask::Cmd::Install.install_casks(
*casks, *casks,
binaries: args.binaries?, binaries: args.binaries?,

View File

@ -314,7 +314,7 @@ installed formulae or, every 30 days, for all formulae.
* `-d`, `--debug`: * `-d`, `--debug`:
If brewing fails, open an interactive debugging session with access to IRB or a shell inside the temporary build directory. If brewing fails, open an interactive debugging session with access to IRB or a shell inside the temporary build directory.
* `-f`, `--force`: * `-f`, `--force`:
Install without checking for previously installed keg-only or non-migrated versions. Install formulae without checking for previously installed keg-only or non-migrated versions. Overwrite existing files when installing casks.
* `-v`, `--verbose`: * `-v`, `--verbose`:
Print the verification and postinstall steps. Print the verification and postinstall steps.
* `--formula`: * `--formula`:
@ -351,6 +351,36 @@ installed formulae or, every 30 days, for all formulae.
Create a Git repository, useful for creating patches to the software. Create a Git repository, useful for creating patches to the software.
* `--cask`: * `--cask`:
Treat all named arguments as casks. Treat all named arguments as casks.
* `--appdir`:
Target location for Applications. Default: `/Applications`
* `--colorpickerdir`:
Target location for Color Pickers. Default: `~/Library/ColorPickers`
* `--prefpanedir`:
Target location for Preference Panes. Default: `~/Library/PreferencePanes`
* `--qlplugindir`:
Target location for QuickLook Plugins. Default: `~/Library/QuickLook`
* `--mdimporterdir`:
Target location for Spotlight Plugins. Default: `~/Library/Spotlight`
* `--dictionarydir`:
Target location for Dictionaries. Default: `~/Library/Dictionaries`
* `--fontdir`:
Target location for Fonts. Default: `~/Library/Fonts`
* `--servicedir`:
Target location for Services. Default: `~/Library/Services`
* `--input_methoddir`:
Target location for Input Methods. Default: `~/Library/Input Methods`
* `--internet_plugindir`:
Target location for Internet Plugins. Default: `~/Library/Internet Plug-Ins`
* `--audio_unit_plugindir`:
Target location for Audio Unit Plugins. Default: `~/Library/Audio/Plug-Ins/Components`
* `--vst_plugindir`:
Target location for VST Plugins. Default: `~/Library/Audio/Plug-Ins/VST`
* `--vst3_plugindir`:
Target location for VST3 Plugins. Default: `~/Library/Audio/Plug-Ins/VST3`
* `--screen_saverdir`:
Target location for Screen Savers. Default: `~/Library/Screen Savers`
* `--language`:
Set language of the Cask to install. The first matching language is used, otherwise the default language on the Cask. The default value is the `language of your system`
* `--[no-]binaries`: * `--[no-]binaries`:
Disable/enable linking of helper executables to `/usr/local/bin`. Default: enabled Disable/enable linking of helper executables to `/usr/local/bin`. Default: enabled
* `--require-sha`: * `--require-sha`:

View File

@ -457,7 +457,7 @@ If brewing fails, open an interactive debugging session with access to IRB or a
. .
.TP .TP
\fB\-f\fR, \fB\-\-force\fR \fB\-f\fR, \fB\-\-force\fR
Install without checking for previously installed keg\-only or non\-migrated versions\. Install formulae without checking for previously installed keg\-only or non\-migrated versions\. Overwrite existing files when installing casks\.
. .
.TP .TP
\fB\-v\fR, \fB\-\-verbose\fR \fB\-v\fR, \fB\-\-verbose\fR
@ -532,6 +532,66 @@ Create a Git repository, useful for creating patches to the software\.
Treat all named arguments as casks\. Treat all named arguments as casks\.
. .
.TP .TP
\fB\-\-appdir\fR
Target location for Applications\. Default: \fB/Applications\fR
.
.TP
\fB\-\-colorpickerdir\fR
Target location for Color Pickers\. Default: \fB~/Library/ColorPickers\fR
.
.TP
\fB\-\-prefpanedir\fR
Target location for Preference Panes\. Default: \fB~/Library/PreferencePanes\fR
.
.TP
\fB\-\-qlplugindir\fR
Target location for QuickLook Plugins\. Default: \fB~/Library/QuickLook\fR
.
.TP
\fB\-\-mdimporterdir\fR
Target location for Spotlight Plugins\. Default: \fB~/Library/Spotlight\fR
.
.TP
\fB\-\-dictionarydir\fR
Target location for Dictionaries\. Default: \fB~/Library/Dictionaries\fR
.
.TP
\fB\-\-fontdir\fR
Target location for Fonts\. Default: \fB~/Library/Fonts\fR
.
.TP
\fB\-\-servicedir\fR
Target location for Services\. Default: \fB~/Library/Services\fR
.
.TP
\fB\-\-input_methoddir\fR
Target location for Input Methods\. Default: \fB~/Library/Input Methods\fR
.
.TP
\fB\-\-internet_plugindir\fR
Target location for Internet Plugins\. Default: \fB~/Library/Internet Plug\-Ins\fR
.
.TP
\fB\-\-audio_unit_plugindir\fR
Target location for Audio Unit Plugins\. Default: \fB~/Library/Audio/Plug\-Ins/Components\fR
.
.TP
\fB\-\-vst_plugindir\fR
Target location for VST Plugins\. Default: \fB~/Library/Audio/Plug\-Ins/VST\fR
.
.TP
\fB\-\-vst3_plugindir\fR
Target location for VST3 Plugins\. Default: \fB~/Library/Audio/Plug\-Ins/VST3\fR
.
.TP
\fB\-\-screen_saverdir\fR
Target location for Screen Savers\. Default: \fB~/Library/Screen Savers\fR
.
.TP
\fB\-\-language\fR
Set language of the Cask to install\. The first matching language is used, otherwise the default language on the Cask\. The default value is the \fBlanguage of your system\fR
.
.TP
\fB\-\-[no\-]binaries\fR \fB\-\-[no\-]binaries\fR
Disable/enable linking of helper executables to \fB/usr/local/bin\fR\. Default: enabled Disable/enable linking of helper executables to \fB/usr/local/bin\fR\. Default: enabled
. .