mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #1248 from Git-Jiro/add_reinstall_cmd_to_cask
add cask reinstall command
This commit is contained in:
commit
606a762344
@ -15,6 +15,7 @@ require "hbc/cli/home"
|
|||||||
require "hbc/cli/info"
|
require "hbc/cli/info"
|
||||||
require "hbc/cli/install"
|
require "hbc/cli/install"
|
||||||
require "hbc/cli/list"
|
require "hbc/cli/list"
|
||||||
|
require "hbc/cli/reinstall"
|
||||||
require "hbc/cli/search"
|
require "hbc/cli/search"
|
||||||
require "hbc/cli/style"
|
require "hbc/cli/style"
|
||||||
require "hbc/cli/uninstall"
|
require "hbc/cli/uninstall"
|
||||||
|
49
Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
Normal file
49
Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
module Hbc
|
||||||
|
class CLI
|
||||||
|
class Reinstall < Install
|
||||||
|
def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
|
||||||
|
count = 0
|
||||||
|
cask_tokens.each do |cask_token|
|
||||||
|
begin
|
||||||
|
cask = Hbc.load(cask_token)
|
||||||
|
|
||||||
|
if cask.installed?
|
||||||
|
# use copy of cask for uninstallation to avoid 'No such file or directory' bug
|
||||||
|
installed_cask = cask
|
||||||
|
latest_installed_version = installed_cask.timestamped_versions.last
|
||||||
|
|
||||||
|
unless latest_installed_version.nil?
|
||||||
|
latest_installed_cask_file = installed_cask.metadata_master_container_path
|
||||||
|
.join(latest_installed_version
|
||||||
|
.join(File::Separator),
|
||||||
|
"Casks", "#{cask_token}.rb")
|
||||||
|
|
||||||
|
# use the same cask file that was used for installation, if possible
|
||||||
|
installed_cask = Hbc.load(latest_installed_cask_file) if latest_installed_cask_file.exist?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Always force uninstallation, ignore method parameter
|
||||||
|
Installer.new(installed_cask, force: true).uninstall
|
||||||
|
end
|
||||||
|
|
||||||
|
Installer.new(cask,
|
||||||
|
force: force,
|
||||||
|
skip_cask_deps: skip_cask_deps,
|
||||||
|
require_sha: require_sha).install
|
||||||
|
count += 1
|
||||||
|
rescue CaskUnavailableError => e
|
||||||
|
warn_unavailable_with_suggestion cask_token, e
|
||||||
|
rescue CaskNoShasumError => e
|
||||||
|
opoo e.message
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
count.zero? ? nil : count == cask_tokens.length
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.help
|
||||||
|
"reinstalls the given Cask"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
27
Library/Homebrew/cask/test/cask/cli/reinstall_test.rb
Normal file
27
Library/Homebrew/cask/test/cask/cli/reinstall_test.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
describe Hbc::CLI::Reinstall do
|
||||||
|
it "allows reinstalling a Cask" do
|
||||||
|
shutup do
|
||||||
|
Hbc::CLI::Install.run("local-transmission")
|
||||||
|
end
|
||||||
|
Hbc.load("local-transmission").must_be :installed?
|
||||||
|
|
||||||
|
shutup do
|
||||||
|
Hbc::CLI::Reinstall.run("local-transmission")
|
||||||
|
end
|
||||||
|
Hbc.load("local-transmission").must_be :installed?
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows reinstalling a non installed Cask" do
|
||||||
|
shutup do
|
||||||
|
Hbc::CLI::Uninstall.run("local-transmission")
|
||||||
|
end
|
||||||
|
Hbc.load("local-transmission").wont_be :installed?
|
||||||
|
|
||||||
|
shutup do
|
||||||
|
Hbc::CLI::Reinstall.run("local-transmission")
|
||||||
|
end
|
||||||
|
Hbc.load("local-transmission").must_be :installed?
|
||||||
|
end
|
||||||
|
end
|
@ -86,6 +86,9 @@ names, and other aspects of this manual are still subject to change.
|
|||||||
If <token> is given, summarize the staged files associated with the
|
If <token> is given, summarize the staged files associated with the
|
||||||
given Cask.
|
given Cask.
|
||||||
|
|
||||||
|
* `reinstall` <token> [ <token> ...]
|
||||||
|
Reinstall the given Cask.
|
||||||
|
|
||||||
* `search` or `-S` [<text> | /<regexp>/]:
|
* `search` or `-S` [<text> | /<regexp>/]:
|
||||||
Without argument, display all Casks available for install, otherwise
|
Without argument, display all Casks available for install, otherwise
|
||||||
perform a substring search of known Cask tokens for <text> or, if the
|
perform a substring search of known Cask tokens for <text> or, if the
|
||||||
|
@ -34,78 +34,65 @@ The tokens returned by \fBsearch\fR are suitable as arguments for most other com
|
|||||||
.
|
.
|
||||||
.SH "COMMANDS"
|
.SH "COMMANDS"
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBaudit\fR [ \fItoken\fR \.\.\. ]
|
\fBaudit\fR [ \fItoken\fR \.\.\. ]: Check the given Casks for installability\. If no tokens are given on the command line, all Casks are audited\.
|
||||||
Check the given Casks for installability\. If no tokens are given on the command line, all Casks are audited\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBcat\fR \fItoken\fR [ \fItoken\fR \.\.\. ]
|
\fBcat\fR \fItoken\fR [ \fItoken\fR \.\.\. ]: Dump the given Cask definition file to the standard output\.
|
||||||
Dump the given Cask definition file to the standard output\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBcleanup\fR [\-\-outdated]
|
\fBcleanup\fR [\-\-outdated]: Clean up cached downloads and tracker symlinks\. With \fB\-\-outdated\fR, only clean up cached downloads older than 10 days old\.
|
||||||
Clean up cached downloads and tracker symlinks\. With \fB\-\-outdated\fR, only clean up cached downloads older than 10 days old\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBcreate\fR \fItoken\fR
|
\fBcreate\fR \fItoken\fR: Generate a Cask definition file for the Cask identified by \fItoken\fR and open a template for it in your favorite editor\.
|
||||||
Generate a Cask definition file for the Cask identified by \fItoken\fR and open a template for it in your favorite editor\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBdoctor\fR or \fBdr\fR
|
\fBdoctor\fR or \fBdr\fR: Check for configuration issues\. Can be useful to upload as a gist for developers along with a bug report\.
|
||||||
Check for configuration issues\. Can be useful to upload as a gist for developers along with a bug report\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBedit\fR \fItoken\fR
|
\fBedit\fR \fItoken\fR: Open the given Cask definition file for editing\.
|
||||||
Open the given Cask definition file for editing\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBfetch\fR [\-\-force] \fItoken\fR [ \fItoken\fR \.\.\. ]
|
\fBfetch\fR [\-\-force] \fItoken\fR [ \fItoken\fR \.\.\. ]: Download remote application files for the given Cask to the local cache\. With \fB\-\-force\fR, force re\-download even if the files are already cached\.
|
||||||
Download remote application files for the given Cask to the local cache\. With \fB\-\-force\fR, force re\-download even if the files are already cached\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBhome\fR or \fBhomepage\fR [ \fItoken\fR \.\.\. ]
|
\fBhome\fR or \fBhomepage\fR [ \fItoken\fR \.\.\. ]: Display the homepage associated with a given Cask in a browser\.
|
||||||
Display the homepage associated with a given Cask in a browser\.
|
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
With no arguments, display the project page \fIhttp://caskroom\.io\fR\.
|
With no arguments, display the project page \fIhttp://caskroom\.io\fR\.
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBinfo\fR or \fBabv\fR \fItoken\fR [ \fItoken\fR \.\.\. ]
|
\fBinfo\fR or \fBabv\fR \fItoken\fR [ \fItoken\fR \.\.\. ]: Display information about the given Cask\.
|
||||||
Display information about the given Cask\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBinstall\fR [\-\-force] [\-\-skip\-cask\-deps] [\-\-require\-sha] \fItoken\fR [ \fItoken\fR \.\.\. ]
|
\fBinstall\fR [\-\-force] [\-\-skip\-cask\-deps] [\-\-require\-sha] \fItoken\fR [ \fItoken\fR \.\.\. ]: Install the given Cask\. With \fB\-\-force\fR, re\-install even if the Cask appears to be already present\. With \fB\-\-skip\-cask\-deps\fR, skip any Cask dependencies\. \fB\-\-require\-sha\fR will abort installation if the Cask does not have a checksum defined\.
|
||||||
Install the given Cask\. With \fB\-\-force\fR, re\-install even if the Cask appears to be already present\. With \fB\-\-skip\-cask\-deps\fR, skip any Cask dependencies\. \fB\-\-require\-sha\fR will abort installation if the Cask does not have a checksum defined\.
|
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
\fItoken\fR is usually the ID of a Cask as returned by \fBbrew cask search\fR, but see \fIOTHER WAYS TO SPECIFY A CASK\fR for variations\.
|
\fItoken\fR is usually the ID of a Cask as returned by \fBbrew cask search\fR, but see \fIOTHER WAYS TO SPECIFY A CASK\fR for variations\.
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBlist\fR or \fBls\fR [\-1] [\-\-versions] [ \fItoken\fR \.\.\. ]
|
\fBlist\fR or \fBls\fR [\-1] [\-\-versions] [ \fItoken\fR \.\.\. ]: Without any arguments, list all installed Casks\. With \fB\-1\fR, always format the output in a single column\. With \fB\-\-versions\fR, show all installed versions\.
|
||||||
Without any arguments, list all installed Casks\. With \fB\-1\fR, always format the output in a single column\. With \fB\-\-versions\fR, show all installed versions\.
|
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
If \fItoken\fR is given, summarize the staged files associated with the given Cask\.
|
If \fItoken\fR is given, summarize the staged files associated with the given Cask\.
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBsearch\fR or \fB\-S\fR [\fItext\fR | /\fIregexp\fR/]
|
\fBreinstall\fR \fItoken\fR [ \fItoken\fR \.\.\.] Reinstall the given Cask\.
|
||||||
Without argument, display all Casks available for install, otherwise perform a substring search of known Cask tokens for \fItext\fR or, if the text is delimited by slashes (/\fIregexp\fR/), it is interpreted as a Ruby regular expression\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBstyle\fR [\-\-fix] [ \fItoken\fR \.\.\. ]
|
\fBsearch\fR or \fB\-S\fR [\fItext\fR | /\fIregexp\fR/]: Without argument, display all Casks available for install, otherwise perform a substring search of known Cask tokens for \fItext\fR or, if the text is delimited by slashes (/\fIregexp\fR/), it is interpreted as a Ruby regular expression\.
|
||||||
Check the given Casks for correct style using RuboCop Cask \fIhttps://github\.com/caskroom/rubocop\-cask\fR\. If no tokens are given on the command line, all Casks are checked\. With \fB\-\-fix\fR, auto\-correct any style errors if possible\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBuninstall\fR or \fBrm\fR or \fBremove\fR [\-\-force] \fItoken\fR [ \fItoken\fR \.\.\. ]
|
\fBstyle\fR [\-\-fix] [ \fItoken\fR \.\.\. ]: Check the given Casks for correct style using RuboCop Cask \fIhttps://github\.com/caskroom/rubocop\-cask\fR\. If no tokens are given on the command line, all Casks are checked\. With \fB\-\-fix\fR, auto\-correct any style errors if possible\.
|
||||||
Uninstall the given Cask\. With \fB\-\-force\fR, uninstall even if the Cask does not appear to be present\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBupdate\fR
|
\fBuninstall\fR or \fBrm\fR or \fBremove\fR [\-\-force] \fItoken\fR [ \fItoken\fR \.\.\. ]: Uninstall the given Cask\. With \fB\-\-force\fR, uninstall even if the Cask does not appear to be present\.
|
||||||
For convenience\. \fBbrew cask update\fR is a synonym for \fBbrew update\fR\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.IP "\(bu" 4
|
||||||
\fBzap\fR \fItoken\fR [ \fItoken\fR \.\.\. ]
|
\fBupdate\fR: For convenience\. \fBbrew cask update\fR is a synonym for \fBbrew update\fR\.
|
||||||
Unconditionally remove \fIall\fR files associated with the given Cask\.
|
.
|
||||||
|
.IP "\(bu" 4
|
||||||
|
\fBzap\fR \fItoken\fR [ \fItoken\fR \.\.\. ]: Unconditionally remove \fIall\fR files associated with the given Cask\.
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
Implicitly performs all actions associated with \fBuninstall\fR, even if the Cask does not appear to be currently installed\.
|
Implicitly performs all actions associated with \fBuninstall\fR, even if the Cask does not appear to be currently installed\.
|
||||||
@ -119,6 +106,8 @@ If the Cask definition contains a \fBzap\fR stanza, performs additional \fBzap\f
|
|||||||
.IP
|
.IP
|
||||||
\fB\fBzap\fR may remove files which are shared between applications\.\fR
|
\fB\fBzap\fR may remove files which are shared between applications\.\fR
|
||||||
.
|
.
|
||||||
|
.IP "" 0
|
||||||
|
.
|
||||||
.SH "OPTIONS"
|
.SH "OPTIONS"
|
||||||
To make these options persistent, see the ENVIRONMENT section, below\.
|
To make these options persistent, see the ENVIRONMENT section, below\.
|
||||||
.
|
.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user