#!/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=] [--stdout=] [--stderr=] (...) #{program_name} -h | --help Options: -h --help Show this screen. -v --version Show version information. -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 -o --stdout= Specify what file should be used for data being sent to stdout when using stdio(3) -r --stderr= Specify what file should be used for data being sent to stderr when using stdio(3) EOS begin options = Docopt::docopt(doc, :version => LaunchAgent::VERSION) agent = LaunchAgent::CLI::OptionParser.new(options, options['']).agent action = agent.loaded? ? :unload : :load agent.send(action) puts '%s "%s"' % [action, agent.args.join(' ')] rescue Docopt::Exit => e puts e.message end