From a4e092a1c49bf7a81244a1f04ef1e115176754cc Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 9 Oct 2016 10:21:07 +0200 Subject: add cask reinstall command --- Library/Homebrew/cask/lib/hbc/cli.rb | 1 + Library/Homebrew/cask/lib/hbc/cli/reinstall.rb | 48 ++++++++++++++++++++++ .../Homebrew/cask/test/cask/cli/reinstall_test.rb | 17 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 Library/Homebrew/cask/lib/hbc/cli/reinstall.rb create mode 100644 Library/Homebrew/cask/test/cask/cli/reinstall_test.rb (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index 2173a52d0..3773ebd93 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -15,6 +15,7 @@ require "hbc/cli/home" require "hbc/cli/info" require "hbc/cli/install" require "hbc/cli/list" +require "hbc/cli/reinstall" require "hbc/cli/search" require "hbc/cli/style" require "hbc/cli/uninstall" diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb new file mode 100644 index 000000000..61a7c2d71 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -0,0 +1,48 @@ +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 diff --git a/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb new file mode 100644 index 000000000..1798adda0 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +describe Hbc::CLI::Reinstall do + it "allows reinstalling a Cask" do + Hbc::CLI::Install.run("local-transmission") + Hbc.load("local-transmission").must_be :installed? + Hbc::CLI::Reinstall.run("local-transmission") + Hbc.load("local-transmission").must_be :installed? + end + + it "allows reinstalling a non installed Cask" do + Hbc::CLI::Uninstall.run("local-transmission") + Hbc.load("local-transmission").wont_be :installed? + Hbc::CLI::Reinstall.run("local-transmission") + Hbc.load("local-transmission").must_be :installed? + end +end -- cgit v1.2.3 From 8f8606b8c84d47da5f3bf4e7128f5e271ac212b1 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Wed, 19 Oct 2016 20:35:44 +0200 Subject: Fix code coverage issue by introducing shutup blocks --- Library/Homebrew/cask/test/cask/cli/reinstall_test.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb index 1798adda0..22f0d23fd 100644 --- a/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb +++ b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb @@ -2,16 +2,26 @@ require "test_helper" describe Hbc::CLI::Reinstall do it "allows reinstalling a Cask" do - Hbc::CLI::Install.run("local-transmission") + shutup do + Hbc::CLI::Install.run("local-transmission") + end Hbc.load("local-transmission").must_be :installed? - Hbc::CLI::Reinstall.run("local-transmission") + + 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 - Hbc::CLI::Uninstall.run("local-transmission") + shutup do + Hbc::CLI::Uninstall.run("local-transmission") + end Hbc.load("local-transmission").wont_be :installed? - Hbc::CLI::Reinstall.run("local-transmission") + + shutup do + Hbc::CLI::Reinstall.run("local-transmission") + end Hbc.load("local-transmission").must_be :installed? end end -- cgit v1.2.3 From 31fb99680026fb285bc69f1641e3fbdbed09ee98 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 23 Oct 2016 09:57:28 +0200 Subject: Remove unncessary semicolon --- Library/Homebrew/cask/lib/hbc/cli/reinstall.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index 61a7c2d71..c98249ca8 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -9,7 +9,7 @@ module Hbc if cask.installed? # use copy of cask for uninstallation to avoid 'No such file or directory' bug - installed_cask = cask; + installed_cask = cask latest_installed_version = installed_cask.timestamped_versions.last unless latest_installed_version.nil? -- cgit v1.2.3 From 32dc78835db1dff9135c3da9bc577f29469fb059 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 23 Oct 2016 20:20:08 +0200 Subject: Add documentation for cask reinstall command --- Library/Homebrew/manpages/brew-cask.1.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index 244a98f3a..117cfc5f1 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -86,6 +86,12 @@ names, and other aspects of this manual are still subject to change. If is given, summarize the staged files associated with the given Cask. + * `reinstall` [ ...] + Reinstall the given Cask. + + is usually the ID of a Cask as returned by `brew cask search`, + but see [OTHER WAYS TO SPECIFY A CASK][] for variations. + * `search` or `-S` [ | //]: Without argument, display all Casks available for install, otherwise perform a substring search of known Cask tokens for or, if the -- cgit v1.2.3 From 95d4a258914867ef6237709dd03971dbec765324 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 23 Oct 2016 20:39:53 +0200 Subject: Fix linting errors --- Library/Homebrew/cask/lib/hbc/cli/reinstall.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index c98249ca8..ac514bd50 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -14,8 +14,9 @@ module Hbc 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") + .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? -- cgit v1.2.3 From 0b8af5771f590bfb5cea7bccd4bd0fc77a973113 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Mon, 24 Oct 2016 05:30:49 +0200 Subject: Remove duplicate description of --- Library/Homebrew/manpages/brew-cask.1.md | 3 --- 1 file changed, 3 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index 117cfc5f1..c2dce22b2 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -89,9 +89,6 @@ names, and other aspects of this manual are still subject to change. * `reinstall` [ ...] Reinstall the given Cask. - is usually the ID of a Cask as returned by `brew cask search`, - but see [OTHER WAYS TO SPECIFY A CASK][] for variations. - * `search` or `-S` [ | //]: Without argument, display all Casks available for install, otherwise perform a substring search of known Cask tokens for or, if the -- cgit v1.2.3