pack_rb 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/pack_rb/executor.rb +47 -0
- data/lib/pack_rb/sub_commands.rb +7 -8
- data/lib/pack_rb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fa9a2e4e584f27505b9c844749b682d7ec2d735
|
4
|
+
data.tar.gz: 10ca1ecf02e460a16ed096aeae8cd5bcf56dd9f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85d6ca9698e520df0ae4a1e365fa621dcdb2884c1aa8cc25f7ff2af1e6fca45da1a239720085484bf2238c510594e3b6e147074a9f081b029890b49cfaa838b7
|
7
|
+
data.tar.gz: d801cb47c6f6f96b0dfa23a378709e20ac9e910cb152709bd311e5a7ddcc7b8648518e71e61ba2009724547391ff793245f2d6116c5ae233e4720c8a8092144a
|
data/README.md
CHANGED
@@ -73,7 +73,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
73
73
|
|
74
74
|
## Contributing
|
75
75
|
|
76
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/manheim/pack_rb.
|
77
77
|
|
78
78
|
|
79
79
|
## License
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module PackRb
|
4
|
+
class Executor
|
5
|
+
# popen3 wrapper to simultaneously stream command output to the
|
6
|
+
# appropriate file descriptor, and capture it.
|
7
|
+
#
|
8
|
+
# @param cmd [String] command to run
|
9
|
+
# @param tpl [String] the template content
|
10
|
+
# @return [Array] - stdout [String], stderr [String], exit code [Fixnum]
|
11
|
+
def self.run_cmd_stream_output(cmd, tpl)
|
12
|
+
all_out = ''
|
13
|
+
all_err = ''
|
14
|
+
exit_status = nil
|
15
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thread|
|
16
|
+
stdin.write(tpl)
|
17
|
+
stdin.close_write
|
18
|
+
begin
|
19
|
+
files = [stdout, stderr]
|
20
|
+
until files.find { |f| !f.eof }.nil?
|
21
|
+
ready = IO.select(files)
|
22
|
+
next unless ready
|
23
|
+
readable = ready[0]
|
24
|
+
readable.each do |f|
|
25
|
+
begin
|
26
|
+
data = f.read_nonblock(512)
|
27
|
+
if f.fileno == stdout.fileno
|
28
|
+
puts data
|
29
|
+
all_out << data
|
30
|
+
else
|
31
|
+
STDERR.puts data
|
32
|
+
all_err << data
|
33
|
+
end
|
34
|
+
rescue EOFError
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue IOError => e
|
40
|
+
STDERR.puts "IOError: #{e}"
|
41
|
+
end
|
42
|
+
exit_status = wait_thread.value.exitstatus
|
43
|
+
end
|
44
|
+
[all_out, all_err, exit_status]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/pack_rb/sub_commands.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'pack_rb/executor'
|
3
2
|
require 'pack_rb/sub_commands/build'
|
4
3
|
require 'pack_rb/sub_commands/inspect'
|
5
4
|
require 'pack_rb/sub_commands/validate'
|
@@ -10,16 +9,16 @@ module PackRb
|
|
10
9
|
include PackRb::SubCommands::Inspect
|
11
10
|
include PackRb::SubCommands::Validate
|
12
11
|
|
12
|
+
# Execute a Packer command via {PackRb::Executor.run_cmd_stream_output}
|
13
|
+
#
|
14
|
+
# @param opts [Hash] options passed to the Packer class
|
15
|
+
#
|
16
|
+
# @return [Array] - stdout [String], stderr [String], exit code [Fixnum]
|
13
17
|
def execute(opts)
|
14
18
|
cmd = opts[:cmd]
|
15
19
|
tpl = opts[:tpl]
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
if status.exitstatus != 0
|
20
|
-
puts out if out
|
21
|
-
puts err if err
|
22
|
-
end
|
21
|
+
PackRb::Executor.run_cmd_stream_output("#{cmd} -", tpl)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
data/lib/pack_rb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pack_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Niesen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- bin/setup
|
101
101
|
- circle.yml
|
102
102
|
- lib/pack_rb.rb
|
103
|
+
- lib/pack_rb/executor.rb
|
103
104
|
- lib/pack_rb/packer.rb
|
104
105
|
- lib/pack_rb/sub_commands.rb
|
105
106
|
- lib/pack_rb/sub_commands/build.rb
|