launch-agent 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -0
- data/bin/launchagent +8 -7
- data/launch-agent.gemspec +1 -1
- data/lib/launch_agent/base.rb +2 -0
- data/lib/launch_agent/cli.rb +8 -4
- data/lib/launch_agent/version.rb +1 -1
- data/spec/cli_spec.rb +1 -1
- data/spec/option_parser_spec.rb +9 -9
- metadata +8 -8
data/README.rdoc
CHANGED
@@ -17,6 +17,16 @@ A library to use launchd easily
|
|
17
17
|
== CLI
|
18
18
|
|
19
19
|
$ launchagent -h
|
20
|
+
Usage:
|
21
|
+
launchagent [--env=<env>] (--daemon | --interval <sec>) [--wdir=<dir>] [--] (<argument>...)
|
22
|
+
launchagent -h | --help
|
23
|
+
|
24
|
+
Options:
|
25
|
+
-h --help Show this screen.
|
26
|
+
-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
|
27
|
+
-w --wdir=<dir> Specify a directory to chdir(2) to before running the job
|
28
|
+
-d --daemon Load as daemon. If it is set, --interval option is ignored.
|
29
|
+
-i --interval=<sec> Causes the job to be started every N seconds
|
20
30
|
|
21
31
|
== Note on Patches/Pull Requests
|
22
32
|
|
data/bin/launchagent
CHANGED
@@ -7,24 +7,25 @@ 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>]
|
10
|
+
#{program_name} [--env=<env>] (--daemon | --interval <sec>) [--wdir=<dir>] (<argument>...)
|
11
11
|
#{program_name} -h | --help
|
12
12
|
|
13
13
|
Options:
|
14
14
|
-h --help Show this screen.
|
15
|
+
-v --version Show version information.
|
15
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
|
16
17
|
-w --wdir=<dir> Specify a directory to chdir(2) to before running the job
|
17
18
|
-d --daemon Load as daemon. If it is set, --interval option is ignored.
|
18
19
|
-i --interval=<sec> Causes the job to be started every N seconds
|
19
20
|
EOS
|
20
21
|
|
21
|
-
options = Docopt(doc, LaunchAgent::VERSION)
|
22
|
-
|
23
22
|
begin
|
24
|
-
|
23
|
+
options = Docopt::docopt(doc, :version => LaunchAgent::VERSION)
|
24
|
+
|
25
|
+
agent = LaunchAgent::CLI::OptionParser.new(options, options['<argument>']).agent
|
25
26
|
action = agent.loaded? ? :unload : :load
|
26
27
|
agent.send(action)
|
27
|
-
puts '%s "%s"' % [action,
|
28
|
-
rescue => e
|
29
|
-
|
28
|
+
puts '%s "%s"' % [action, agent.args.join(' ')]
|
29
|
+
rescue Docopt::Exit => e
|
30
|
+
puts e.message
|
30
31
|
end
|
data/launch-agent.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = LaunchAgent::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency('plist')
|
19
|
-
gem.add_dependency('docopt')
|
19
|
+
gem.add_dependency('docopt', '0.5.0')
|
20
20
|
gem.add_development_dependency('rspec', ['~> 2.8.0'])
|
21
21
|
gem.add_development_dependency('rake')
|
22
22
|
end
|
data/lib/launch_agent/base.rb
CHANGED
data/lib/launch_agent/cli.rb
CHANGED
@@ -4,15 +4,19 @@ module LaunchAgent
|
|
4
4
|
def initialize(opts, argv)
|
5
5
|
@opts = opts
|
6
6
|
@argv = argv
|
7
|
+
|
8
|
+
if @argv[0] == '--'
|
9
|
+
@argv.shift
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
def agent
|
10
14
|
raise 'full command must be supplied' if @argv.empty?
|
11
15
|
|
12
|
-
daemon = @opts[
|
13
|
-
interval = @opts[
|
14
|
-
env = (@opts[
|
15
|
-
wdir = @opts[
|
16
|
+
daemon = @opts['--daemon']
|
17
|
+
interval = @opts['--interval']
|
18
|
+
env = (@opts['--env'] || '').split(',')
|
19
|
+
wdir = @opts['--wdir']
|
16
20
|
agent = nil
|
17
21
|
|
18
22
|
if daemon
|
data/lib/launch_agent/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe 'CLI' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should load/unload daemon-like agent' do
|
14
|
-
command = File.expand_path(File.dirname(__FILE__) + '/../bin/launchagent --daemon --env FOO=BAR ruby foo.rb')
|
14
|
+
command = File.expand_path(File.dirname(__FILE__) + '/../bin/launchagent --daemon --env FOO=BAR -- ruby foo.rb')
|
15
15
|
|
16
16
|
system(command)
|
17
17
|
|
data/spec/option_parser_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe CLI::OptionParser do
|
|
23
23
|
describe 'empty argv' do
|
24
24
|
let(:opts) do
|
25
25
|
@opts.merge(
|
26
|
-
|
26
|
+
'--daemon' => true)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should raise if argv is empty' do
|
@@ -36,8 +36,8 @@ describe CLI::OptionParser do
|
|
36
36
|
describe 'empty env' do
|
37
37
|
let(:opts) do
|
38
38
|
@opts.merge(
|
39
|
-
|
40
|
-
|
39
|
+
'--env' => nil,
|
40
|
+
'--daemon' => true)
|
41
41
|
end
|
42
42
|
|
43
43
|
it_should_behave_like 'valid agent'
|
@@ -58,7 +58,7 @@ describe CLI::OptionParser do
|
|
58
58
|
describe 'daemon' do
|
59
59
|
let(:opts) do
|
60
60
|
@opts.merge(
|
61
|
-
|
61
|
+
'--daemon' => true)
|
62
62
|
end
|
63
63
|
|
64
64
|
it_should_behave_like 'valid agent'
|
@@ -77,8 +77,8 @@ describe CLI::OptionParser do
|
|
77
77
|
describe 'wdir' do
|
78
78
|
let(:opts) do
|
79
79
|
@opts.merge(
|
80
|
-
|
81
|
-
|
80
|
+
'--daemon' => true,
|
81
|
+
'--wdir' => '/foo/bar')
|
82
82
|
end
|
83
83
|
|
84
84
|
it_should_behave_like 'valid agent'
|
@@ -94,8 +94,8 @@ describe CLI::OptionParser do
|
|
94
94
|
describe 'env' do
|
95
95
|
let(:opts) do
|
96
96
|
@opts.merge(
|
97
|
-
|
98
|
-
|
97
|
+
'--daemon' => true,
|
98
|
+
'--env' => 'FOO=BAR,BAR=BAZ')
|
99
99
|
end
|
100
100
|
|
101
101
|
it_should_behave_like 'valid agent'
|
@@ -111,7 +111,7 @@ describe CLI::OptionParser do
|
|
111
111
|
describe 'interval' do
|
112
112
|
let(:opts) do
|
113
113
|
@opts.merge(
|
114
|
-
|
114
|
+
'--interval' => "120")
|
115
115
|
end
|
116
116
|
|
117
117
|
it_should_behave_like 'valid agent'
|
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.
|
4
|
+
version: 0.7.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-
|
12
|
+
date: 2012-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plist
|
@@ -32,17 +32,17 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.5.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.5.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: 3228195630547528638
|
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:
|
128
|
+
hash: 3228195630547528638
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
131
|
rubygems_version: 1.8.24
|