Class: LaunchAgent::CLI::OptionParser
- Inherits:
-
Object
- Object
- LaunchAgent::CLI::OptionParser
- Defined in:
- lib/launch_agent/cli.rb
Instance Method Summary collapse
- #agent ⇒ Object
-
#initialize(opts, argv) ⇒ OptionParser
constructor
A new instance of OptionParser.
Constructor Details
#initialize(opts, argv) ⇒ OptionParser
Returns a new instance of OptionParser.
4 5 6 7 8 9 10 11 |
# File 'lib/launch_agent/cli.rb', line 4 def initialize(opts, argv) @opts = opts @argv = argv if @argv[0] == '--' @argv.shift end end |
Instance Method Details
#agent ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/launch_agent/cli.rb', line 13 def agent raise 'full command must be supplied' if @argv.empty? daemon = @opts['--daemon'] interval = @opts['--interval'] env = (@opts['--env'] || '').split(',') wdir = @opts['--wdir'] stdout_path = @opts['--stdout'] stderr_path = @opts['--stderr'] agent = nil if daemon agent = LaunchAgent::Daemon.new(*@argv) elsif interval agent = LaunchAgent::Periodic.new(interval.to_i, *@argv) else raise 'at least one of --daemon and --interval must be set' end agent['EnvironmentVariables'] = env.inject({}) do |memo, e| k, v = e.split('=') memo[k] = v memo end if wdir agent['WorkingDirectory'] = File.(wdir) end if stdout_path agent['StandardOutPath'] = File.(stdout_path) end if stderr_path agent['StandardErrorPath'] = File.(stderr_path) end agent end |