frontkick 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +14 -0
- data/example/env.rb +7 -0
- data/lib/frontkick.rb +2 -2
- data/lib/frontkick/command.rb +16 -6
- data/lib/frontkick/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93bb374c56521e783c36f3e8fb2dc6dce5e16747
|
4
|
+
data.tar.gz: c24802f00fe4911982148fff88d6ae7609ec21a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1dbd382e8c11c8cb220a4fe35cfb845c709aaa74b990abaf73e02d913cddca353143db60c96ac0f1c34aee3f516942b26bfbc23c8a0f58520cc67ae2966d63e
|
7
|
+
data.tar.gz: 807825ab7a7b3157358cd3345d5a1bdf6a0e9c7ef3d5b9e1376db1beaa50365384f1d839c02986c40ad00388f03db1cb7464c8b042b9e4bcc6687ce2b9ceaf16
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,20 @@ ruby
|
|
70
70
|
└─ echo
|
71
71
|
```
|
72
72
|
|
73
|
+
NOTE: This interface is different with Kernel.spawn or Open3.popen3. They works with no shell if multiple arguments are given rather than an array as:
|
74
|
+
|
75
|
+
```
|
76
|
+
spawn('echo', '*')
|
77
|
+
```
|
78
|
+
|
79
|
+
### Environment Variables
|
80
|
+
|
81
|
+
You can pass environment variables as a hash for the 1st argument as [spawn](https://ruby-doc.org/core-2.4.0/Kernel.html#method-i-spawn).
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
result = Frontkick.exec({"FOO"=>"BAR"}, ["echo", "*"])
|
85
|
+
```
|
86
|
+
|
73
87
|
### Dry Run Option
|
74
88
|
|
75
89
|
```ruby
|
data/example/env.rb
ADDED
data/lib/frontkick.rb
CHANGED
@@ -5,8 +5,8 @@ require 'frontkick/command'
|
|
5
5
|
require 'frontkick/result'
|
6
6
|
|
7
7
|
module Frontkick
|
8
|
-
def self.exec(
|
9
|
-
::Frontkick::Command.exec(
|
8
|
+
def self.exec(*env_cmd, **opts, &block)
|
9
|
+
::Frontkick::Command.exec(*env_cmd, opts, &block)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.process_wait(pid)
|
data/lib/frontkick/command.rb
CHANGED
@@ -4,7 +4,18 @@ require 'shellwords'
|
|
4
4
|
|
5
5
|
module Frontkick
|
6
6
|
class Command
|
7
|
-
def self.exec(
|
7
|
+
def self.exec(*env_cmd, **opts, &block)
|
8
|
+
env, cmd = env_cmd.size >= 2 ? env_cmd : [{}, env_cmd.first]
|
9
|
+
# With this conversion,
|
10
|
+
#
|
11
|
+
# popen3(env, *cmd_array, opts)
|
12
|
+
#
|
13
|
+
# works for both interface of:
|
14
|
+
#
|
15
|
+
# popen3(env, command, opts)
|
16
|
+
# popen3(env, program, *args, opts)
|
17
|
+
cmd_array = cmd.is_a?(Array) ? cmd : [cmd]
|
18
|
+
|
8
19
|
opts[:timeout_kill] = true unless opts.has_key?(:timeout_kill) # default: true
|
9
20
|
|
10
21
|
exit_code, duration = nil
|
@@ -32,11 +43,10 @@ module Frontkick
|
|
32
43
|
err = StringIO.new
|
33
44
|
end
|
34
45
|
|
35
|
-
cmd_array = cmd.kind_of?(Array) ? cmd : [cmd]
|
36
|
-
command = "#{cmd_array.first} #{Shellwords.shelljoin(cmd_array[1..-1])}"
|
37
|
-
|
38
46
|
if opts[:dry_run]
|
39
|
-
|
47
|
+
stdout = env.map {|k,v| "#{k}=#{v} " }.join('')
|
48
|
+
stdout << "#{cmd_array.first} #{Shellwords.shelljoin(cmd_array[1..-1])}"
|
49
|
+
return Result.new(:stdout => stdout, :stderr => '', :exit_code => 0, :duration => 0)
|
40
50
|
end
|
41
51
|
|
42
52
|
popen3_opts = self.popen3_opts(opts)
|
@@ -45,7 +55,7 @@ module Frontkick
|
|
45
55
|
begin
|
46
56
|
::Timeout.timeout(opts[:timeout], Frontkick::TimeoutLocal) do # nil is for no timeout
|
47
57
|
duration = Benchmark.realtime do
|
48
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3(*cmd_array, popen3_opts)
|
58
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(env, *cmd_array, popen3_opts)
|
49
59
|
out_thr = Thread.new {
|
50
60
|
begin
|
51
61
|
while true
|
data/lib/frontkick/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frontkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
70
|
- example/dry_run.rb
|
71
|
+
- example/env.rb
|
71
72
|
- example/kill_child.rb
|
72
73
|
- example/popen3_options.rb
|
73
74
|
- example/redirect_without_shell.rb
|