Skip to content

Commit

Permalink
services support
Browse files Browse the repository at this point in the history
  • Loading branch information
leoj3n committed Dec 14, 2013
1 parent c9b2927 commit 7432aff
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Additional fields you might need for special use-cases:
| `qlplugin` | relative path to a QuickLook plugin that should be linked into the `~/Library/QuickLook` folder on installation
| `font` | relative path to a font that should be linked into the `~/Library/Fonts` folder on installation
| `widget` | relative path to a widget that should be linked into the `~/Library/Widgets` folder on installation
| `service` | relative path to a service that should be linked into the `~/Library/Services` folder on installation
| `nested_container` | relative path to an inner container that must be extracted before moving on with the installation; this allows us to support dmg inside tar, zip inside dmg, etc.
| `caveats` | a Ruby block providing the user with Cask-specific information at install time
| `after_install` | a Ruby block containing postflight install operations
Expand Down
7 changes: 7 additions & 0 deletions Casks/calc-service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CalcService < Cask
url 'https://s3.amazonaws.com/DTWebsiteSupport/download/freeware/calcservice/3.4/CalcService.zip'
homepage 'http://www.devontechnologies.com/products/freeware.html#c1111'
version '3.4'
sha1 'ce6102a42b01929794e235cb9f42cbcb6c7e9077'
service 'CalcService.service'
end
2 changes: 2 additions & 0 deletions lib/cask/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Cask::Artifact; end
require 'cask/artifact/prefpane'
require 'cask/artifact/qlplugin'
require 'cask/artifact/widget'
require 'cask/artifact/service'


module Cask::Artifact
Expand All @@ -28,6 +29,7 @@ def self.artifacts
Cask::Artifact::Qlplugin,
Cask::Artifact::Font,
Cask::Artifact::Widget,
Cask::Artifact::Service,
Cask::Artifact::Block,
]
end
Expand Down
41 changes: 41 additions & 0 deletions lib/cask/artifact/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Cask::Artifact::Service < Cask::Artifact::Base
def self.me?(cask)
cask.artifacts[:service].any?
end

def install
@cask.artifacts[:service].each { |service| link(service) }
end

def uninstall
@cask.artifacts[:service].each { |service| unlink(service) }
end

def link(service_relative_path)
source = @cask.destination_path.join(service_relative_path)
target = Cask.servicedir.join(source.basename)

return unless preflight_checks(source, target)
ohai "Linking service #{source.basename} to #{target}"
@command.run!('/bin/ln', :args => ['-hfs', source, target])
end

def preflight_checks(source, target)
if target.exist? && !target.symlink?
ohai "It seems there is already a service at #{target}; not linking."
false
end
unless source.exist?
raise "it seems the symlink source is not there: #{source}"
end
true
end

def unlink(service_relative_path)
linked_path = Cask.servicedir.join(Pathname(service_relative_path).basename)
if linked_path.exist? && linked_path.symlink?
ohai "Removing service link: #{linked_path}"
linked_path.delete
end
end
end
3 changes: 3 additions & 0 deletions lib/cask/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def self.parser
opts.on("--widgetdir=MANDATORY") do |v|
Cask.widgetdir = Pathname(v).expand_path
end
opts.on("--servicedir=MANDATORY") do |v|
Cask.servicedir = Pathname(v).expand_path
end
opts.on("--debug") do |v|
@debug = true
end
Expand Down
1 change: 1 addition & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def artifacts
:font,
:uninstall,
:widget,
:service,
:colorpicker,
]

Expand Down
8 changes: 8 additions & 0 deletions lib/cask/locations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def colorpickerdir=(_colorpickerdir)
@colorpickerdir = _colorpickerdir
end

def servicedir
@servicedir ||= Pathname.new('~/Library/Services').expand_path
end

def servicedir=(_servicedir)
@servicedir = _servicedir
end

def default_tap
@default_tap ||= 'phinze-cask'
end
Expand Down
14 changes: 14 additions & 0 deletions test/cask/cli/options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@
Cask.widgetdir.must_equal Pathname('/some/path/bar')
end

it "supports setting the servicedir" do
Cask::CLI.process_options %w{help --servicedir=/some/path/foo}

Cask.servicedir.must_equal Pathname('/some/path/foo')
end

it "supports setting the servicedir from ENV" do
ENV['HOMEBREW_CASK_OPTS'] = "--servicedir=/some/path/bar"

Cask::CLI.process_options %w{help}

Cask.servicedir.must_equal Pathname('/some/path/bar')
end

it "allows additional options to be passed through" do
rest = Cask::CLI.process_options %w{edit foo --create --appdir=/some/path/qux}

Expand Down

0 comments on commit 7432aff

Please sign in to comment.