#!/usr/bin/env ruby require 'rubygems' require 'launch_agent' require 'docopt' program_name = File.basename($0) doc =<<-EOS Usage: #{program_name} [--env=] (--daemon | --interval ) [--wdir=] [--] (...) #{program_name} -h | --help Options: -h --help Show this screen. -e --env= Additional environmental variables to be set before running the job. Can specify multiple value with comma. e.g. FOO=bar,BAR=baz -w --wdir= Specify a directory to chdir(2) to before running the job -d --daemon Load as daemon. If it is set, --interval option is ignored. -i --interval= Causes the job to be started every N seconds EOS options = Docopt(doc, LaunchAgent::VERSION) begin agent = LaunchAgent::CLI::OptionParser.new(options, ARGV).agent action = agent.loaded? ? :unload : :load agent.send(action) puts '%s "%s"' % [action, ARGV.join(' ')] rescue => e abort e.message end