launch-agent 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ require 'docopt'
7
7
  program_name = File.basename($0)
8
8
  doc =<<-EOS
9
9
  Usage:
10
- #{program_name} [--env=<env>] (--daemon | --interval <sec>) [--wdir=<dir>] (<argument>...)
10
+ #{program_name} [--env=<env>] (--daemon | --interval <sec>) [--wdir=<dir>] [--stdout=<path>] [--stderr=<path>] (<argument>...)
11
11
  #{program_name} -h | --help
12
12
 
13
13
  Options:
@@ -15,8 +15,10 @@ Options:
15
15
  -v --version Show version information.
16
16
  -e --env=<env> Additional environmental variables to be set before running the job. Can specify multiple value with comma. e.g. FOO=bar,BAR=baz
17
17
  -w --wdir=<dir> Specify a directory to chdir(2) to before running the job
18
- -d --daemon Load as daemon. If it is set, --interval option is ignored.
18
+ -d --daemon Load as daemon. If it is set, --interval option is ignored
19
19
  -i --interval=<sec> Causes the job to be started every N seconds
20
+ -o --stdout=<path> Specify what file should be used for data being sent to stdout when using stdio(3)
21
+ -r --stderr=<path> Specify what file should be used for data being sent to stderr when using stdio(3)
20
22
  EOS
21
23
 
22
24
  begin
@@ -13,11 +13,13 @@ module LaunchAgent
13
13
  def agent
14
14
  raise 'full command must be supplied' if @argv.empty?
15
15
 
16
- daemon = @opts['--daemon']
17
- interval = @opts['--interval']
18
- env = (@opts['--env'] || '').split(',')
19
- wdir = @opts['--wdir']
20
- agent = nil
16
+ daemon = @opts['--daemon']
17
+ interval = @opts['--interval']
18
+ env = (@opts['--env'] || '').split(',')
19
+ wdir = @opts['--wdir']
20
+ stdout_path = @opts['--stdout']
21
+ stderr_path = @opts['--stderr']
22
+ agent = nil
21
23
 
22
24
  if daemon
23
25
  agent = LaunchAgent::Daemon.new(*@argv)
@@ -37,6 +39,14 @@ module LaunchAgent
37
39
  agent['WorkingDirectory'] = File.expand_path(wdir)
38
40
  end
39
41
 
42
+ if stdout_path
43
+ agent['StandardOutPath'] = File.expand_path(stdout_path)
44
+ end
45
+
46
+ if stderr_path
47
+ agent['StandardErrorPath'] = File.expand_path(stderr_path)
48
+ end
49
+
40
50
  agent
41
51
  end
42
52
  end
@@ -1,4 +1,3 @@
1
1
  module LaunchAgent
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
4
-
@@ -108,6 +108,40 @@ describe CLI::OptionParser do
108
108
  end
109
109
  end
110
110
 
111
+ describe '--stdout' do
112
+ let(:opts) do
113
+ @opts.merge(
114
+ '--daemon' => true,
115
+ '--stdout' => '~/foo/bar.log')
116
+ end
117
+
118
+ it_should_behave_like 'valid agent'
119
+
120
+ it 'should parse env option' do
121
+ agent = CLI::OptionParser.new(opts, @argv).agent
122
+ plist = agent2plist(agent)
123
+
124
+ plist['StandardOutPath'].should eql(File.expand_path('~/foo/bar.log'))
125
+ end
126
+ end
127
+
128
+ describe '--stderr' do
129
+ let(:opts) do
130
+ @opts.merge(
131
+ '--daemon' => true,
132
+ '--stderr' => '~/foo/bar.log')
133
+ end
134
+
135
+ it_should_behave_like 'valid agent'
136
+
137
+ it 'should parse env option' do
138
+ agent = CLI::OptionParser.new(opts, @argv).agent
139
+ plist = agent2plist(agent)
140
+
141
+ plist['StandardErrorPath'].should eql(File.expand_path('~/foo/bar.log'))
142
+ end
143
+ end
144
+
111
145
  describe 'interval' do
112
146
  let(:opts) do
113
147
  @opts.merge(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launch-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-02 00:00:00.000000000 Z
12
+ date: 2012-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plist
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: 3228195630547528638
119
+ hash: -1931962325568098184
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: 3228195630547528638
128
+ hash: -1931962325568098184
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.24