frontkick 0.5.3 → 0.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bb5e819a8afaf32b404b81f3b4d0792aa90f7b9
4
- data.tar.gz: 9a35e8fafa3cfecde913653eaf4611a9ace3b70a
3
+ metadata.gz: 93bb374c56521e783c36f3e8fb2dc6dce5e16747
4
+ data.tar.gz: c24802f00fe4911982148fff88d6ae7609ec21a2
5
5
  SHA512:
6
- metadata.gz: 628155e7ae55b811fee9f9727f429b5a6e8b50bf28d722618583b8d82627ce60640ac2263dda02d4c43d75ad03a9ac474483a5c0a170586b27c55e656321bfe8
7
- data.tar.gz: 5baf25776ba2790a21c4f9156fdc78fe960fff48dee5357ad6b7e8e655b24549baff06f48c9be1ce66048ac7f0e6087f0e98dbc9aca9463b911480baf21f53dd
6
+ metadata.gz: c1dbd382e8c11c8cb220a4fe35cfb845c709aaa74b990abaf73e02d913cddca353143db60c96ac0f1c34aee3f516942b26bfbc23c8a0f58520cc67ae2966d63e
7
+ data.tar.gz: 807825ab7a7b3157358cd3345d5a1bdf6a0e9c7ef3d5b9e1376db1beaa50365384f1d839c02986c40ad00388f03db1cb7464c8b042b9e4bcc6687ce2b9ceaf16
@@ -1,3 +1,9 @@
1
+ # 0.5.4 (2017/01/12)
2
+
3
+ Enhancements:
4
+
5
+ - Support env argument
6
+
1
7
  # 0.5.3 (2017/01/12)
2
8
 
3
9
  Fixes:
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
@@ -0,0 +1,7 @@
1
+ require 'frontkick'
2
+
3
+ result = Frontkick.exec({'FOO'=>'foo'}, 'env | grep FOO')
4
+ puts result.stdout
5
+
6
+ result = Frontkick.exec({'FOO'=>'foo'}, 'env | grep FOO', {dry_run: true})
7
+ puts result.stdout
@@ -5,8 +5,8 @@ require 'frontkick/command'
5
5
  require 'frontkick/result'
6
6
 
7
7
  module Frontkick
8
- def self.exec(cmd, opts = {}, &block)
9
- ::Frontkick::Command.exec(cmd, opts, &block)
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)
@@ -4,7 +4,18 @@ require 'shellwords'
4
4
 
5
5
  module Frontkick
6
6
  class Command
7
- def self.exec(cmd, opts = {}, &block)
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
- return Result.new(:stdout => command, :stderr => '', :exit_code => 0, :duration => 0)
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
@@ -1,3 +1,3 @@
1
1
  module Frontkick
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
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.3
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