spud 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shell.rb +20 -11
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e82f5c891574a3fc3f13aa2b46005c7deafbf6720d378b4432726b3358e65dda
4
- data.tar.gz: 9e46fcd73f03b45bc7bf8ff79a6f15aac02535ec02349112320fbf9003cae213
3
+ metadata.gz: ff2253281ad17fa26000da387d071fca88fe39e6c01913573bf1aa78148c9302
4
+ data.tar.gz: 449e2aead6ea9686659c8b928ca9f4fa07f582156d30e2ae24bbc5680382cd58
5
5
  SHA512:
6
- metadata.gz: 0acce351760b00b50ca4ae4b0734143d1745aa5f2c81cc35c968b2e86186a5fa0a5f2138e6ca095ab7404220bd74b8abaa053a2985baa237e170164df71043f5
7
- data.tar.gz: 075957df7f73c4cf6022ffc0c8c7f28acd31e94f4963e25c875534b3e72c965cf505af6c1bc74a58d0b54896b4b0451c10c3452e2fad252b66b2eeb1404d3920
6
+ metadata.gz: 3f29e51971b0f78eb223e0561bc28a641fa167d72a5e10f996752fffefe8ead8c8fbb09707a24b2192c72b341dd039711808cfe2d6b7dbe78e5cb416c71075a8
7
+ data.tar.gz: 244352f4d935f8f00bc307b88f810743358e1eed079c9f7ef8ffabaca55df1929e9eb7933c5ae76a29bdfa4f9037a519b1ee205e592e49ed3e49f1207a1d4f51
data/lib/shell.rb CHANGED
@@ -1,25 +1,34 @@
1
+ require 'stringio'
1
2
  require 'open3'
2
3
 
3
4
  module Spud
4
5
  class Shell < String
5
- attr_accessor :status
6
-
7
- def initialize(cmd, silent: false)
6
+ def initialize(cmd, silent: false, wait: false)
8
7
  output = StringIO.new
9
8
 
10
- _, out, @thread = Open3.popen2e(cmd)
11
- @status = @thread.value
12
- while line = out.gets
13
- puts line
14
- output.puts line
9
+ stdin, out, @status = Open3.popen2e(cmd)
10
+ @thread = Thread.new do
11
+ while line = out.gets
12
+ puts line unless silent
13
+ output.puts line
14
+ super(output.string)
15
+ end
16
+
17
+ out.close
18
+ stdin.close
15
19
  end
16
20
 
17
- super(output.string)
21
+ @thread.join if wait
22
+ end
23
+
24
+ def status
25
+ @status.value
18
26
  end
19
27
 
20
28
  def kill!
21
- thread.kill
22
- thread.join
29
+ Process.kill('KILL', @status.pid)
30
+ @thread.kill
31
+ @thread.join
23
32
  end
24
33
  end
25
34
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spud
2
- VERSION = '0.1.14'
2
+ VERSION = '0.1.15'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Booth