-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2970 from voanhduy1512/fetch_command
CLI - Fetch
- Loading branch information
Showing
6 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Cask::CLI::Fetch | ||
def self.run(*args) | ||
raise CaskUnspecifiedError if args.empty? | ||
cask_names = args.reject { |a| a.chars.first == '-' } | ||
force = args.include? '--force' | ||
|
||
cask_names.each do |cask_name| | ||
ohai "Fetching resources for Cask #{cask_name}" | ||
cask = Cask.load(cask_name) | ||
@downloaded_path = Cask::Download.new(cask).perform force | ||
ohai "Success! Downloaded to -> #{@downloaded_path}" | ||
end | ||
end | ||
|
||
def self.help | ||
"downloads Cask resources to local cache" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'test_helper' | ||
|
||
describe Cask::CLI::Fetch do | ||
let(:local_transmission) do | ||
Cask.load('local-transmission') | ||
end | ||
|
||
let(:local_caffeine) do | ||
Cask.load('local-caffeine') | ||
end | ||
|
||
it "allows download the installer of a cask" do | ||
shutup do | ||
Cask::CLI::Fetch.run('local-transmission', 'local-caffeine') | ||
end | ||
Cask::CurlDownloadStrategy.new(local_transmission).cached_location.must_be :exist? | ||
Cask::CurlDownloadStrategy.new(local_caffeine).cached_location.must_be :exist? | ||
end | ||
|
||
it "prevents double fetch (without nuking existing installation)" do | ||
download_stategy = Cask::CurlDownloadStrategy.new(local_transmission) | ||
|
||
shutup do | ||
Cask::Download.new(local_transmission).perform | ||
end | ||
old_ctime = File.stat(download_stategy.cached_location).ctime | ||
|
||
shutup do | ||
Cask::CLI::Fetch.run('local-transmission') | ||
end | ||
new_ctime = File.stat(download_stategy.cached_location).ctime | ||
|
||
old_ctime.to_i.must_equal new_ctime.to_i | ||
|
||
end | ||
|
||
it "allows double fetch with --force" do | ||
shutup do | ||
Cask::Download.new(local_transmission).perform | ||
end | ||
|
||
download_stategy = Cask::CurlDownloadStrategy.new(local_transmission) | ||
old_ctime = File.stat(download_stategy.cached_location).ctime | ||
sleep(1) | ||
|
||
shutup do | ||
Cask::CLI::Fetch.run('local-transmission','--force') | ||
end | ||
download_stategy = Cask::CurlDownloadStrategy.new(local_transmission) | ||
new_ctime = File.stat(download_stategy.cached_location).ctime | ||
|
||
# new_ctime.to_i.must_be :>, old_ctime.to_i | ||
new_ctime.to_i.must_be :>, old_ctime.to_i | ||
end | ||
|
||
it "properly handles casks that are not present" do | ||
lambda { | ||
shutup do | ||
Cask::CLI::Fetch.run('notacask') | ||
end | ||
}.must_raise CaskUnavailableError | ||
end | ||
|
||
it "raises an exception when no cask is specified" do | ||
lambda { | ||
shutup do | ||
Cask::CLI::Fetch.run | ||
end | ||
}.must_raise CaskUnspecifiedError | ||
end | ||
end |