komenda 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/lib/komenda/process.rb +6 -6
- data/lib/komenda/process_builder.rb +10 -10
- data/lib/komenda/result.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 539e892cf6dd52f871008d73d4597f549c40664a
|
4
|
+
data.tar.gz: 6421357e13b63bb9e3c59f45532cd72b8e4ea4db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9c596b3f1c0cf1c50630ca6044793f85be884fb78367b1250840d7f90626cef45a1610d1044cddcabfb3a47089720bac0dc792a7ba4787df0d2d58dcf47685d
|
7
|
+
data.tar.gz: 5d0bd13566dfc652623f33240611830c1cf0fa205ba355e8ac98af28c4530d64c494db093201b5b94792065d11ae76faa4340b19c0fc59e699b202391753ffb9
|
data/README.md
CHANGED
@@ -25,18 +25,25 @@ result.success? # => true
|
|
25
25
|
result.pid # => 32157
|
26
26
|
```
|
27
27
|
The program and its arguments can be passed as an array:
|
28
|
-
```ruby
|
28
|
+
```ruby
|
29
29
|
result = Komenda.run(['echo', '-n', 'hello'])
|
30
30
|
result.output # => "hello"
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
### Run options
|
34
|
+
The `run()` method has a second argument `options`.
|
35
|
+
```ruby
|
36
|
+
result = Komenda.run('date', fail_on_fail: true)
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
The following options can be configured:
|
34
41
|
- **`env`** (Hash): Additional environment variables to set.
|
35
|
-
- **`use_bundler_env`** (Boolean): Use the environment
|
42
|
+
- **`use_bundler_env`** (Boolean): Use the [environment of the current bundle](http://www.cargomedia.ch/2016/03/18/reset-bundler-environment.html). Defaults to `false`.
|
36
43
|
- **`cwd`** (String): Directory to change to before running the process.
|
37
44
|
- **`fail_on_fail`** (Boolean): Whether to raise an error when the exit code is not "0". Defaults to `false`.
|
38
45
|
|
39
|
-
###
|
46
|
+
### Asynchronous running
|
40
47
|
The `create()` method creates a `Process` which can be `run()` (or `start()`ed as a Thread).
|
41
48
|
```
|
42
49
|
process = Komenda.create('date')
|
@@ -67,9 +74,3 @@ Run the tests:
|
|
67
74
|
```
|
68
75
|
bundle exec rake spec
|
69
76
|
```
|
70
|
-
|
71
|
-
TODO
|
72
|
-
----
|
73
|
-
Add options for:
|
74
|
-
- Passing STDIN
|
75
|
-
- Making `run()` fail when exit status is not '0'
|
data/lib/komenda/process.rb
CHANGED
@@ -20,16 +20,16 @@ module Komenda
|
|
20
20
|
|
21
21
|
# @return [Thread]
|
22
22
|
def start
|
23
|
-
|
23
|
+
raise 'Already started' if started?
|
24
24
|
@thread = Thread.new { run_process(@process_builder) }
|
25
25
|
end
|
26
26
|
|
27
27
|
# @return [Komenda::Result]
|
28
28
|
def wait_for
|
29
|
-
|
29
|
+
raise 'Process not started' unless started?
|
30
30
|
@thread.join
|
31
31
|
if @process_builder.fail_on_fail && !result.success?
|
32
|
-
|
32
|
+
raise "Process failed with exit status `#{result.exitstatus}` and output:\n#{result.output}"
|
33
33
|
end
|
34
34
|
result
|
35
35
|
end
|
@@ -42,7 +42,7 @@ module Komenda
|
|
42
42
|
|
43
43
|
# @return [Integer]
|
44
44
|
def pid
|
45
|
-
|
45
|
+
raise 'No PID available' if @pid.nil?
|
46
46
|
@pid
|
47
47
|
end
|
48
48
|
|
@@ -58,8 +58,8 @@ module Komenda
|
|
58
58
|
|
59
59
|
# @return [Komenda::Result]
|
60
60
|
def result
|
61
|
-
|
62
|
-
|
61
|
+
raise 'Process not started' unless started?
|
62
|
+
raise 'Process not finished' unless finished?
|
63
63
|
Komenda::Result.new(@output, @exit_status)
|
64
64
|
end
|
65
65
|
|
@@ -35,11 +35,11 @@ module Komenda
|
|
35
35
|
|
36
36
|
# @param [String, Array<String>] command
|
37
37
|
def command=(command)
|
38
|
-
if command.is_a?(Array)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
@command = if command.is_a?(Array)
|
39
|
+
command.map { |v| String(v) }
|
40
|
+
else
|
41
|
+
String(command)
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
45
45
|
# @param [Hash] env
|
@@ -69,11 +69,11 @@ module Komenda
|
|
69
69
|
|
70
70
|
# @return [Hash]
|
71
71
|
def env_final
|
72
|
-
if !use_bundler_env && Object.const_defined?('Bundler')
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
env_original = if !use_bundler_env && Object.const_defined?('Bundler')
|
73
|
+
bundler_clean_env
|
74
|
+
else
|
75
|
+
ENV.to_hash
|
76
|
+
end
|
77
77
|
env_original.merge(env)
|
78
78
|
end
|
79
79
|
|
data/lib/komenda/result.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: komenda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cargo Media
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: events
|
@@ -87,14 +87,14 @@ dependencies:
|
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0.
|
90
|
+
version: 0.41.2
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.
|
97
|
+
version: 0.41.2
|
98
98
|
description: Convenience wrapper around `Open3` to run shell commands in Ruby.
|
99
99
|
email: hello@cargomedia.ch
|
100
100
|
executables: []
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.5.1
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Convenience wrapper around `Open3` to run shell commands in Ruby.
|