command_utils 0.2.1 → 0.3.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/command_utils.rb +36 -9
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4991e3855f226e37e49caf964e057ba3344dba28
4
- data.tar.gz: df365e0070852ec25222cc916631bbd8a3f16b0b
3
+ metadata.gz: 3845dc2af885cf859dbc3f1afc1c2a0dd7ef31e4
4
+ data.tar.gz: 3359ba253daa038a08d4d3247ccd40c2a48d16ac
5
5
  SHA512:
6
- metadata.gz: e0709414a5649afbd1999eeb46daf7e940c246fdc111aa7df37bd5c83a907fce11f162aee29faeb57c6f7ec5dcdade4e68cd29194b1f94f58dd931aa9d54c830
7
- data.tar.gz: 43aee5e4542f6c67df965151797cda5513ec140512ec03a7e16e157140be82182e2197f7e3d26775fd942130e0a2a0298fec0455c9438ca7344e696766f02a75
6
+ metadata.gz: c79aa92e07443ddcaf7b986347d5facfccceb2bc1a7d5f70cc7bf3cbdb79ee0234e8eee773697d303364dc605ad533f8d6313f84fde299ac9e3ef2936f075942
7
+ data.tar.gz: a18f88fc4fcfb06266e7102e958040472a413ca50e6baf68e6a67abd58c513e695e9a767376fb8627620a3d0433526c7404acd24c69bd8c842df18327ebd5ee5
data/lib/command_utils.rb CHANGED
@@ -5,9 +5,22 @@ require_relative 'command_utils/line_buffer'
5
5
  # All methods which execute given command, raise NonZeroStatus if its return is not 0.
6
6
  class CommandUtils
7
7
 
8
+ # call-seq:
9
+ # new([env,] command...)
10
+ #
8
11
  # Takes command in same format supported by Process#spawn.
9
- def initialize *command
10
- @command = command
12
+ def initialize *args
13
+ first = args.first
14
+ if first.kind_of? Hash
15
+ @env = args.shift
16
+ @command = args
17
+ elsif first.respond_to? :to_hash
18
+ @env = args.shift.to_hash
19
+ @command = args
20
+ else
21
+ @env = nil
22
+ @command = args
23
+ end
11
24
  yield self if block_given?
12
25
  end
13
26
 
@@ -36,9 +49,12 @@ class CommandUtils
36
49
  end
37
50
  end
38
51
 
52
+ # call-seq:
53
+ # each_output([env,] command...) { |stream, data| ... }
54
+ #
39
55
  # Wrapper for CommandUtils#each_output
40
- def self.each_output *command, &block # :yields: stream, data
41
- self.new(*command).each_output(&block)
56
+ def self.each_output *args, &block # :yields: stream, data
57
+ self.new(*args).each_output(&block)
42
58
  end
43
59
 
44
60
  # Execute command, yielding to given block, each time there is a new line available.
@@ -67,9 +83,12 @@ class CommandUtils
67
83
  stderr_lb.flush
68
84
  end
69
85
 
86
+ # call-seq:
87
+ # each_line([env,] command...) { |stream, data| ... }
88
+ #
70
89
  # Wrapper for CommandUtils#each_line
71
- def self.each_line *command, &block # :yields: stream, data
72
- self.new(*command).each_line(&block)
90
+ def self.each_line *args, &block # :yields: stream, data
91
+ self.new(*args).each_line(&block)
73
92
  end
74
93
 
75
94
  # Execute command, logging its output, line buffered, to given Logger object.
@@ -88,9 +107,12 @@ class CommandUtils
88
107
  end
89
108
  end
90
109
 
110
+ # call-seq:
111
+ # logger_exec([env,] command..., options)
112
+ #
91
113
  # Wrapper for CommandUtils@logger_exec
92
- def self.logger_exec command, options
93
- self.new(command).logger_exec(options)
114
+ def self.logger_exec *args, options
115
+ self.new(*args).logger_exec(options)
94
116
  end
95
117
 
96
118
  private
@@ -104,8 +126,13 @@ class CommandUtils
104
126
  def spawn
105
127
  @stdout_read, @stdout_write = IO.pipe
106
128
  @stderr_read, @stderr_write = IO.pipe
129
+ spawn_args = if @env
130
+ [@env] + @command
131
+ else
132
+ @command
133
+ end
107
134
  @pid = Process.spawn(
108
- *@command,
135
+ *spawn_args,
109
136
  in: :close,
110
137
  out: @stdout_write.fileno,
111
138
  err: @stderr_write.fileno,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Pugliese Ornellas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2015-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec