cocaine 0.3.0 → 0.3.1
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.
- data/.travis.yml +0 -2
- data/LICENSE +1 -1
- data/NEWS.md +6 -1
- data/README.md +25 -1
- data/cocaine.gemspec +1 -1
- data/lib/cocaine/command_line.rb +21 -11
- data/lib/cocaine/version.rb +1 -1
- data/spec/cocaine/command_line_spec.rb +32 -1
- metadata +12 -10
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
@@ -3,7 +3,7 @@ LICENSE
|
|
3
3
|
|
4
4
|
The MIT License
|
5
5
|
|
6
|
-
Copyright (c)
|
6
|
+
Copyright (c) 2011-2012 Jon Yurek and thoughtbot, inc.
|
7
7
|
|
8
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
9
|
of this software and associated documentation files (the "Software"), to deal
|
data/NEWS.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
New for 0.3.1:
|
2
|
+
|
3
|
+
* Made the `Runner` manually swappable, in case `ProcessRunner` doesn't work
|
4
|
+
for some reason.
|
5
|
+
* Fixed copyright years.
|
6
|
+
|
1
7
|
New for 0.3.0:
|
2
8
|
|
3
9
|
* Support blank arguments.
|
@@ -5,6 +11,5 @@ New for 0.3.0:
|
|
5
11
|
* Add `CommandLine#exit_status`.
|
6
12
|
* Automatically use `POSIX::Spawn` if available.
|
7
13
|
* Add `CommandLine#environment` as a hash of extra `ENV` data..
|
8
|
-
* Add `CommandLine#environment=` to set that hash.
|
9
14
|
* Add `CommandLine#runner` which produces an object that responds to `#call`.
|
10
15
|
* Fix a race condition but only on Ruby 1.9.
|
data/README.md
CHANGED
@@ -125,6 +125,30 @@ processes. For applications with large heaps the gain can be
|
|
125
125
|
significant. To include `posix-spawn`, simply add it to your `Gemfile` or,
|
126
126
|
if you don't use bundler, install the gem.
|
127
127
|
|
128
|
+
## Runners
|
129
|
+
|
130
|
+
Cocaine will attempt to choose from among 3 different ways of running commands.
|
131
|
+
The simplest is using backticks, and is the default in 1.8. In Ruby 1.9, it
|
132
|
+
will attempt to use `Process.spawn`. And, as mentioned above, if the
|
133
|
+
`posix-spawn` gem is installed, it will attempt to use that. If for some reason
|
134
|
+
one of the `.spawn` runners don't work for you, you can override them manually
|
135
|
+
by setting a new runner, like so:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
Cocaine::CommandLine.runner = Cocaine::BackticksRunner.new
|
139
|
+
```
|
140
|
+
|
141
|
+
And if you really want to, you can define your own Runner, though I can't
|
142
|
+
imagine why you would.
|
143
|
+
|
144
|
+
### JRuby Caveat
|
145
|
+
|
146
|
+
If you get `Error::ECHILD` errors and are using JRuby, there is a very good
|
147
|
+
chance that the error is actually in JRuby. This was brought to our attention
|
148
|
+
in https://github.com/thoughtbot/cocaine/issues/24 and probably fixed in
|
149
|
+
http://jira.codehaus.org/browse/JRUBY-6162. You *will* want to use the
|
150
|
+
`BackticksRunner` if you are unable to update JRuby.
|
151
|
+
|
128
152
|
## Feedback
|
129
153
|
|
130
154
|
*Security* concerns must be privately emailed to
|
@@ -136,7 +160,7 @@ Question? Idea? Problem? Bug? Comment? Concern? Like using question marks?
|
|
136
160
|
|
137
161
|
## License
|
138
162
|
|
139
|
-
Copyright 2011 Jon Yurek and thoughtbot, inc. This is free software, and
|
163
|
+
Copyright 2011-2012 Jon Yurek and thoughtbot, inc. This is free software, and
|
140
164
|
may be redistributed under the terms specified in the
|
141
165
|
[LICENSE](https://github.com/thoughtbot/cocaine/blob/master/LICENSE)
|
142
166
|
file.
|
data/cocaine.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.author = "Jon Yurek"
|
9
9
|
s.email = "jyurek@thoughtbot.com"
|
10
|
-
s.homepage = "http://
|
10
|
+
s.homepage = "http://github.com/thoughtbot/cocaine"
|
11
11
|
s.summary = "A small library for doing (command) lines"
|
12
12
|
s.description = "A small library for doing (command) lines"
|
13
13
|
|
data/lib/cocaine/command_line.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cocaine
|
2
2
|
class CommandLine
|
3
3
|
class << self
|
4
|
-
attr_accessor :logger
|
4
|
+
attr_accessor :logger, :runner
|
5
5
|
|
6
6
|
def path
|
7
7
|
@supplemental_path
|
@@ -24,6 +24,18 @@ module Cocaine
|
|
24
24
|
def environment
|
25
25
|
@supplemental_environment ||= {}
|
26
26
|
end
|
27
|
+
|
28
|
+
def runner
|
29
|
+
@runner || best_runner
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def best_runner
|
35
|
+
return PosixRunner.new if posix_spawn_available?
|
36
|
+
return ProcessRunner.new if Process.respond_to?(:spawn)
|
37
|
+
BackticksRunner.new
|
38
|
+
end
|
27
39
|
end
|
28
40
|
@environment = {}
|
29
41
|
|
@@ -33,11 +45,11 @@ module Cocaine
|
|
33
45
|
@binary = binary.dup
|
34
46
|
@params = params.dup
|
35
47
|
@options = options.dup
|
48
|
+
@runner = @options.delete(:runner) || self.class.runner
|
36
49
|
@logger = @options.delete(:logger) || self.class.logger
|
37
50
|
@swallow_stderr = @options.delete(:swallow_stderr)
|
38
|
-
@expected_outcodes = @options.delete(:expected_outcodes)
|
39
|
-
@
|
40
|
-
@runner = best_runner
|
51
|
+
@expected_outcodes = @options.delete(:expected_outcodes) || [0]
|
52
|
+
@environment = @options.delete(:environment) || {}
|
41
53
|
end
|
42
54
|
|
43
55
|
def command
|
@@ -68,19 +80,17 @@ module Cocaine
|
|
68
80
|
end
|
69
81
|
|
70
82
|
def unix?
|
71
|
-
|
83
|
+
RbConfig::CONFIG['host_os'] !~ /mswin|mingw/
|
72
84
|
end
|
73
85
|
|
74
86
|
private
|
75
87
|
|
76
88
|
def execute(command)
|
77
|
-
runner.call(command,
|
89
|
+
runner.call(command, environment)
|
78
90
|
end
|
79
91
|
|
80
|
-
def
|
81
|
-
|
82
|
-
return ProcessRunner.new if Process.respond_to?(:spawn)
|
83
|
-
BackticksRunner.new
|
92
|
+
def environment
|
93
|
+
self.class.environment.merge(@environment)
|
84
94
|
end
|
85
95
|
|
86
96
|
def interpolate(pattern, vars)
|
@@ -97,7 +107,7 @@ module Cocaine
|
|
97
107
|
end
|
98
108
|
|
99
109
|
def invalid_variables
|
100
|
-
%w(expected_outcodes swallow_stderr logger)
|
110
|
+
%w(expected_outcodes swallow_stderr logger environment)
|
101
111
|
end
|
102
112
|
|
103
113
|
def interpolation(vars, key)
|
data/lib/cocaine/version.rb
CHANGED
@@ -26,7 +26,7 @@ describe Cocaine::CommandLine do
|
|
26
26
|
output.should match(%r{/path/to/command/dir})
|
27
27
|
output.should match(%r{/some/other/path})
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "temporarily changes specified environment variables" do
|
31
31
|
Cocaine::CommandLine.environment['TEST'] = 'Hello, world!'
|
32
32
|
cmd = Cocaine::CommandLine.new("ruby", "-e 'puts ENV[%{TEST}]'")
|
@@ -34,6 +34,21 @@ describe Cocaine::CommandLine do
|
|
34
34
|
output.should match(%r{Hello, world!})
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'changes environment variables for the command line' do
|
38
|
+
Cocaine::CommandLine.environment['TEST'] = 'Hello, world!'
|
39
|
+
cmd = Cocaine::CommandLine.new("ruby",
|
40
|
+
"-e 'puts ENV[%{TEST}]'",
|
41
|
+
:environment => {'TEST' => 'Hej hej'})
|
42
|
+
output = cmd.run
|
43
|
+
output.should match(%r{Hej hej})
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'passes the existing environment variables through to the runner' do
|
47
|
+
command = Cocaine::CommandLine.new('echo', '$HOME')
|
48
|
+
output = command.run
|
49
|
+
output.chomp.should_not == ''
|
50
|
+
end
|
51
|
+
|
37
52
|
it "can interpolate quoted variables into the command line's parameters" do
|
38
53
|
cmd = Cocaine::CommandLine.new("convert",
|
39
54
|
":one :{two}",
|
@@ -215,5 +230,21 @@ describe Cocaine::CommandLine do
|
|
215
230
|
cmd = Cocaine::CommandLine.new("echo", "hello")
|
216
231
|
cmd.runner.class.should == Cocaine::CommandLine::PosixRunner
|
217
232
|
end
|
233
|
+
|
234
|
+
it "uses the BackticksRunner if the posix-spawn gem is available, but we told it to use Backticks all the time" do
|
235
|
+
Cocaine::CommandLine.stubs(:posix_spawn_available?).returns(true)
|
236
|
+
Cocaine::CommandLine.runner = Cocaine::CommandLine::BackticksRunner.new
|
237
|
+
|
238
|
+
cmd = Cocaine::CommandLine.new("echo", "hello")
|
239
|
+
cmd.runner.class.should == Cocaine::CommandLine::BackticksRunner
|
240
|
+
end
|
241
|
+
|
242
|
+
it "uses the BackticksRunner if the posix-spawn gem is available, but we told it to use Backticks" do
|
243
|
+
Cocaine::CommandLine.stubs(:posix_spawn_available?).returns(true)
|
244
|
+
|
245
|
+
cmd = Cocaine::CommandLine.new("echo", "hello", :runner => Cocaine::CommandLine::BackticksRunner.new)
|
246
|
+
cmd.runner.class.should == Cocaine::CommandLine::BackticksRunner
|
247
|
+
end
|
248
|
+
|
218
249
|
end
|
219
250
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocaine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
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-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -121,7 +121,7 @@ files:
|
|
121
121
|
- spec/spec_helper.rb
|
122
122
|
- spec/support/stub_os.rb
|
123
123
|
- spec/support/with_exitstatus.rb
|
124
|
-
homepage: http://
|
124
|
+
homepage: http://github.com/thoughtbot/cocaine
|
125
125
|
licenses: []
|
126
126
|
post_install_message:
|
127
127
|
rdoc_options: []
|
@@ -133,22 +133,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
133
|
- - ! '>='
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
|
-
segments:
|
137
|
-
- 0
|
138
|
-
hash: 2124621343266974199
|
139
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
137
|
none: false
|
141
138
|
requirements:
|
142
139
|
- - ! '>='
|
143
140
|
- !ruby/object:Gem::Version
|
144
141
|
version: '0'
|
145
|
-
segments:
|
146
|
-
- 0
|
147
|
-
hash: 2124621343266974199
|
148
142
|
requirements: []
|
149
143
|
rubyforge_project:
|
150
144
|
rubygems_version: 1.8.24
|
151
145
|
signing_key:
|
152
146
|
specification_version: 3
|
153
147
|
summary: A small library for doing (command) lines
|
154
|
-
test_files:
|
148
|
+
test_files:
|
149
|
+
- spec/cocaine/command_line/runners/backticks_runner_spec.rb
|
150
|
+
- spec/cocaine/command_line/runners/posix_runner_spec.rb
|
151
|
+
- spec/cocaine/command_line/runners/process_runner_spec.rb
|
152
|
+
- spec/cocaine/command_line_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/support/stub_os.rb
|
155
|
+
- spec/support/with_exitstatus.rb
|
156
|
+
has_rdoc:
|