23 changed files with 173 additions and 106 deletions
@ -0,0 +1 @@ |
|||||
|
.ruby-version |
@ -1 +0,0 @@ |
|||||
1.8.7-p358 |
|
@ -1,19 +0,0 @@ |
|||||
module Cask::Actions |
|
||||
def linkapps |
|
||||
Pathname.glob("#{destination_path}/**/*.app").each do |app| |
|
||||
destination = Cask.appdir.join(app.basename) |
|
||||
target = destination_path.join(app) |
|
||||
if destination.symlink? |
|
||||
# destination exists but is symlink; removing and relinking |
|
||||
ohai "[#{self}] linking #{File.basename(destination)}" |
|
||||
destination.delete |
|
||||
destination.make_symlink(target) |
|
||||
elsif destination.directory? || destination.file? |
|
||||
ohai "[#{self}] NOT linking #{File.basename(destination)} - already exists" |
|
||||
else |
|
||||
ohai "[#{self}] linking #{File.basename(destination)}" |
|
||||
destination.make_symlink(target) |
|
||||
end |
|
||||
end |
|
||||
end |
|
||||
end |
|
@ -0,0 +1,37 @@ |
|||||
|
class Cask |
||||
|
class AppLinker |
||||
|
def initialize(cask) |
||||
|
@cask = cask |
||||
|
end |
||||
|
|
||||
|
def link |
||||
|
@cask.linkable_apps.each do |app| |
||||
|
link_app(app) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def unlink |
||||
|
@cask.linkable_apps.each do |app| |
||||
|
unlink_app(app) |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
def unlink_app(app) |
||||
|
app_path = Cask.appdir.join(app.basename) |
||||
|
app_path.delete if app_path.exist? |
||||
|
end |
||||
|
|
||||
|
def remove_app_extension(path) |
||||
|
Pathname(path.to_s.sub(/\.app$/, '')) |
||||
|
end |
||||
|
|
||||
|
def link_app(app) |
||||
|
app_path = Cask.appdir.join(app.basename) |
||||
|
if app_path.directory? |
||||
|
ohai "It seems there is already an app at #{app_path}; not linking." |
||||
|
return |
||||
|
end |
||||
|
`ln -s #{app} #{app_path}` |
||||
|
end |
||||
|
end |
||||
|
end |
@ -1,42 +0,0 @@ |
|||||
require 'test_helper' |
|
||||
|
|
||||
describe Cask::Actions do |
|
||||
describe 'linkapps' do |
|
||||
before do |
|
||||
@caffeine = Cask.load('local-caffeine') |
|
||||
shutup { Cask::Installer.install(@caffeine) } |
|
||||
@app = @caffeine.destination_path/'Caffeine.app' |
|
||||
end |
|
||||
|
|
||||
after do |
|
||||
Cask::Installer.uninstall(@caffeine) |
|
||||
end |
|
||||
|
|
||||
it "works with an application in the root directory" do |
|
||||
shutup do |
|
||||
@caffeine.linkapps |
|
||||
end |
|
||||
|
|
||||
expected_symlink = Cask.appdir/'Caffeine.app' |
|
||||
expected_symlink.must_be :exist? |
|
||||
expected_symlink.must_be :symlink? |
|
||||
expected_symlink.readlink.must_equal @app |
|
||||
end |
|
||||
|
|
||||
it "works with an application in a subdir" do |
|
||||
appsubdir = @caffeine.destination_path/'subdir' |
|
||||
appsubdir.mkpath |
|
||||
FileUtils.mv @app, appsubdir |
|
||||
appinsubdir = appsubdir/'Caffeine.app' |
|
||||
|
|
||||
shutup do |
|
||||
@caffeine.linkapps |
|
||||
end |
|
||||
|
|
||||
expected_symlink = Cask.appdir/'Caffeine.app' |
|
||||
expected_symlink.must_be :exist? |
|
||||
expected_symlink.must_be :symlink? |
|
||||
expected_symlink.readlink.must_equal appinsubdir |
|
||||
end |
|
||||
end |
|
||||
end |
|
@ -0,0 +1,50 @@ |
|||||
|
require 'test_helper' |
||||
|
|
||||
|
describe Cask::AppLinker do |
||||
|
describe 'linkapps' do |
||||
|
before do |
||||
|
@caffeine = Cask.load('local-caffeine') |
||||
|
shutup { Cask::Installer.install(@caffeine) } |
||||
|
@app = @caffeine.destination_path/'Caffeine.app' |
||||
|
end |
||||
|
|
||||
|
after do |
||||
|
Cask::Installer.uninstall(@caffeine) |
||||
|
end |
||||
|
|
||||
|
it "works with an application in the root directory" do |
||||
|
Cask::AppLinker.new(@caffeine).link |
||||
|
TestHelper.valid_alias?(Cask.appdir/'Caffeine.app').must_equal true |
||||
|
end |
||||
|
|
||||
|
it "works with an application in a subdir" do |
||||
|
appsubdir = @caffeine.destination_path/'subdir' |
||||
|
appsubdir.mkpath |
||||
|
FileUtils.mv @app, appsubdir |
||||
|
appinsubdir = appsubdir/'Caffeine.app' |
||||
|
|
||||
|
Cask::AppLinker.new(@caffeine).link |
||||
|
|
||||
|
TestHelper.valid_alias?(Cask.appdir/'Caffeine.app').must_equal true |
||||
|
end |
||||
|
|
||||
|
it "only uses linkables when they are specified" do |
||||
|
FileUtils.cp_r @app, @app.sub('Caffeine.app', 'CaffeineAgain.app') |
||||
|
|
||||
|
Cask::AppLinker.new(@caffeine).link |
||||
|
|
||||
|
TestHelper.valid_alias?(Cask.appdir/'Caffeine.app').must_equal true |
||||
|
TestHelper.valid_alias?(Cask.appdir/'CaffeineAgain.app').must_equal false |
||||
|
end |
||||
|
|
||||
|
it "avoids clobbering an existing app by linking over it" do |
||||
|
(Cask.appdir/'Caffeine.app').mkpath |
||||
|
|
||||
|
shutup do |
||||
|
Cask::AppLinker.new(@caffeine).link |
||||
|
end |
||||
|
|
||||
|
(Cask.appdir/'Caffeine.app').directory?.must_equal true |
||||
|
end |
||||
|
end |
||||
|
end |
@ -0,0 +1,15 @@ |
|||||
|
require 'test_helper' |
||||
|
|
||||
|
describe Cask::CLI do |
||||
|
it "lists the taps for casks that show up in two taps" do |
||||
|
Cask::CLI.nice_listing(%w[ |
||||
|
phinze-cask/adium |
||||
|
phinze-cask/google-chrome |
||||
|
passcod-cask/adium |
||||
|
]).must_equal(%w[ |
||||
|
google-chrome |
||||
|
passcod-cask/adium |
||||
|
phinze-cask/adium |
||||
|
]) |
||||
|
end |
||||
|
end |
@ -1,33 +1,27 @@ |
|||||
require 'test_helper' |
require 'test_helper' |
||||
|
|
||||
describe Cask::CLI::Linkapps do |
describe Cask::CLI::Linkapps do |
||||
it "only links casks mentioned when arguments are provided" do |
before do |
||||
caffeine = Cask.load('local-caffeine') |
|
||||
transmission = Cask.load('local-transmission') |
|
||||
|
|
||||
shutup do |
shutup do |
||||
|
caffeine = Cask.load('local-caffeine') |
||||
|
transmission = Cask.load('local-transmission') |
||||
|
|
||||
Cask::Installer.install caffeine |
Cask::Installer.install caffeine |
||||
Cask::Installer.install transmission |
Cask::Installer.install transmission |
||||
|
|
||||
Cask::CLI::Linkapps.run('local-transmission') |
|
||||
end |
end |
||||
|
|
||||
(Cask.appdir/"Transmission.app").must_be :symlink? |
|
||||
(Cask.appdir/"Caffeine.app").wont_be :symlink? |
|
||||
end |
end |
||||
|
|
||||
it "links all installed casks when no arguments supplied" do |
it "only links casks mentioned when arguments are provided" do |
||||
caffeine = Cask.load('local-caffeine') |
Cask::CLI::Linkapps.run('local-transmission') |
||||
transmission = Cask.load('local-transmission') |
|
||||
|
|
||||
shutup do |
TestHelper.valid_alias?(Cask.appdir/"Transmission.app").must_equal true |
||||
Cask::Installer.install caffeine |
TestHelper.valid_alias?(Cask.appdir/"Caffeine.app").wont_equal true |
||||
Cask::Installer.install transmission |
end |
||||
|
|
||||
Cask::CLI::Linkapps.run |
it "links all installed casks when no arguments supplied" do |
||||
end |
Cask::CLI::Linkapps.run |
||||
|
|
||||
(Cask.appdir/"Transmission.app").must_be :symlink? |
TestHelper.valid_alias?(Cask.appdir/"Transmission.app").must_equal true |
||||
(Cask.appdir/"Caffeine.app").must_be :symlink? |
TestHelper.valid_alias?(Cask.appdir/"Caffeine.app").must_equal true |
||||
end |
end |
||||
end |
end |
||||
|
Loading…
Reference in new issue