From 169ac2d413d1a354e1a273759fac61faa2357c17 Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Thu, 23 May 2019 15:20:24 +0800 Subject: [PATCH 1/4] cask: add new --cache command It prints the file used to cache Casks. This can be used to help users to install casks with their files downloaded from outside brew. See #6157. --- Library/Homebrew/cask/cmd.rb | 1 + Library/Homebrew/cask/cmd/--cache.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Library/Homebrew/cask/cmd/--cache.rb diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index efb5566fa3..d69687900f 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -10,6 +10,7 @@ require "cask/config" require "cask/cmd/options" require "cask/cmd/abstract_command" +require "cask/cmd/--cache" require "cask/cmd/audit" require "cask/cmd/automerge" require "cask/cmd/cat" diff --git a/Library/Homebrew/cask/cmd/--cache.rb b/Library/Homebrew/cask/cmd/--cache.rb new file mode 100644 index 0000000000..d3aaf8e027 --- /dev/null +++ b/Library/Homebrew/cask/cmd/--cache.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "cask/download" + +module Cask + class Cmd + class Cache < AbstractCommand + def self.command_name + "--cache" + end + + def initialize(*) + super + raise CaskUnspecifiedError if args.empty? + end + + def run + casks.each do |cask| + puts Download.new(cask).downloader.cached_location + end + end + + def self.help + "display the file used to cache the Cask" + end + end + end +end From 8ad48f56e85682c5223aabc1d484f32e569f2ca8 Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Thu, 23 May 2019 15:22:41 +0800 Subject: [PATCH 2/4] add test for `brew cask --cache` --- .../Homebrew/test/cask/cmd/--cache_spec.rb | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Library/Homebrew/test/cask/cmd/--cache_spec.rb diff --git a/Library/Homebrew/test/cask/cmd/--cache_spec.rb b/Library/Homebrew/test/cask/cmd/--cache_spec.rb new file mode 100644 index 0000000000..c84f9ed3ac --- /dev/null +++ b/Library/Homebrew/test/cask/cmd/--cache_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + +describe Cask::Cmd::Cache, :cask do + let(:local_transmission) { + Cask::CaskLoader.load(cask_path("local-transmission")) + } + + let(:local_caffeine) { + Cask::CaskLoader.load(cask_path("local-caffeine")) + } + + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + + it "prints the file used to cache the Cask" do + transmission_location = CurlDownloadStrategy.new( + local_transmission.url.to_s, local_transmission.token, local_transmission.version, + cache: Cask::Cache.path, **local_transmission.url.specs + ).cached_location + caffeine_location = CurlDownloadStrategy.new( + local_caffeine.url.to_s, local_caffeine.token, local_caffeine.version, + cache: Cask::Cache.path, **local_caffeine.url.specs + ).cached_location + + expect do + described_class.run("local-transmission", "local-caffeine") + end.to output("#{transmission_location}\n#{caffeine_location}\n").to_stdout + end + + it "properly handles Casks that are not present" do + expect { + described_class.run("notacask") + }.to raise_error(Cask::CaskUnavailableError) + end +end From ebec9d35d90d98e22b299e87ff10f36591cbcdde Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Thu, 23 May 2019 15:26:22 +0800 Subject: [PATCH 3/4] manpages: add `brew cask --cache` command --- Library/Homebrew/manpages/brew-cask.1.md | 3 +++ manpages/brew-cask.1 | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index c7c1e09dc1..69af6d81e4 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -21,6 +21,9 @@ graphical user interface. ## COMMANDS + * `--cache` [ ... ]: + Display the file used to cache the Cask identified by . + * `audit` [--language=[, ... ]] [ ... ]: Check the given Casks for installability. If no tokens are given on the command line, all Casks are audited. diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index 59916b7f77..23febd9eed 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -25,6 +25,10 @@ Uninstall Cask identified by \fItoken\fR\. .SH "COMMANDS" . .TP +\fB\-\-cache\fR \fItoken\fR [ \fItoken\fR \.\.\. ] +Display the file used to cache the Cask identified by \fItoken\fR\. +. +.TP \fBaudit\fR [\-\-language=\fIiso\-language\fR[,\fIiso\-language\fR \.\.\. ]] [ \fItoken\fR \.\.\. ] Check the given Casks for installability\. If no tokens are given on the command line, all Casks are audited\. . From ba517e07e21f400451655350938f36137a6253ab Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Thu, 23 May 2019 15:50:55 +0800 Subject: [PATCH 4/4] fix `brew style` error Spec path should end with cask/cmd/cache*_spec.rb. describe Cask::Cmd::Cache, :cask do ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- Library/Homebrew/test/cask/cmd/{--cache_spec.rb => cache_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Library/Homebrew/test/cask/cmd/{--cache_spec.rb => cache_spec.rb} (100%) diff --git a/Library/Homebrew/test/cask/cmd/--cache_spec.rb b/Library/Homebrew/test/cask/cmd/cache_spec.rb similarity index 100% rename from Library/Homebrew/test/cask/cmd/--cache_spec.rb rename to Library/Homebrew/test/cask/cmd/cache_spec.rb