#!/usr/bin/env ruby require 'launch_agent' require 'git-style-binary/command' GitStyleBinary.primary do version "launch-agent #{LaunchAgent::VERSION}" short_desc "load/unload a launchd agent" banner <<-EOS Usage: #{command.full_name} #{all_options_string} {full command} Load/Unload a launchd agent EOS opt :env, "additional environmental variables to be set before running the job. can specify multiple times. e.g. RAILS_ENV=development", :type => String, :multi => true opt :daemon, "load as daemon. if it is set, --interval option is ignored", :default => false opt :wdir, "specify a directory to chdir(2) to before running the job", :type => String opt :interval, "causes the job to be started every N seconds", :type => Integer run do |command| begin agent = LaunchAgent::CLI::OptionParser.new(command.opts, command.argv).agent action = agent.loaded? ? :unload : :load agent.send(action) puts '%s "%s"' % [action, command.argv.join(' ')] rescue => e abort e.message end end end