execute 0.1.0 → 0.1.1
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/lib/IOAdapter.rb +14 -0
- data/lib/cmd.rb +43 -18
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0544f6e92540ff7ab8d005b3474208a896741889
|
4
|
+
data.tar.gz: 4ba1872358af9e977c6442e0f26df575e07a1646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa1dfd84665ea2ab0e0e3d7a9f09ca796bdb88fe5ae46ed3515cd48e365c38fd795b84c8c0ee7923ae85d86e6a9614270a8c361238c43e62ce101315c0c3e22f
|
7
|
+
data.tar.gz: 6ed1745bf90e2c48f7bbd70224a6c7dc42ba8c3397e74301ac371510d40124f97b1e9747e8cebc05c356ba8e64638cfc300e5c7da08a549b55fa53ec7c1fd80d
|
data/lib/IOAdapter.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'tempfile'
|
3
|
+
class IOAdapter < DelegateClass(IO)
|
4
|
+
attr_accessor :output_buffer
|
5
|
+
def initialize(io)
|
6
|
+
__setobj__(io)
|
7
|
+
@output_buffer = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def write(string)
|
11
|
+
@output_buffer << string
|
12
|
+
self.__getobj__.write(string)
|
13
|
+
end
|
14
|
+
end
|
data/lib/cmd.rb
CHANGED
@@ -1,32 +1,57 @@
|
|
1
1
|
require 'open3'
|
2
|
+
require 'sys/proctable'
|
3
|
+
require_relative 'IOAdapter.rb'
|
2
4
|
|
3
5
|
class CMD < Hash
|
6
|
+
private
|
7
|
+
@@default_options = nil
|
8
|
+
|
9
|
+
def self.initialize_defaults
|
10
|
+
@@default_options = { echo_command: true, echo_output: true, ignore_exit_code: false, debug: false }
|
11
|
+
end
|
12
|
+
|
13
|
+
public
|
4
14
|
def initialize(cmd, options=nil)
|
5
15
|
self[:output] = ''
|
6
16
|
self[:error] = ''
|
7
|
-
|
8
|
-
|
9
|
-
self[
|
10
|
-
|
11
|
-
self[:command]=cmd
|
17
|
+
initialize_defaults if(@@default_options.nil?)
|
18
|
+
|
19
|
+
@@default_options.each { |key, value| self[key] = value}
|
12
20
|
options.each { |key, value| self[key] = value} unless(options.nil?)
|
21
|
+
self[:command]=cmd
|
22
|
+
end
|
23
|
+
|
24
|
+
public
|
25
|
+
def self.default_options(hash)
|
26
|
+
initialize_defaults
|
27
|
+
hash.each { |key, value| @@default_options[key] = value}
|
13
28
|
end
|
14
29
|
|
15
30
|
def execute
|
16
|
-
begin
|
17
|
-
puts self[:command]
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
#begin
|
32
|
+
puts self[:command] if(self[:echo_command])
|
33
|
+
|
34
|
+
output = {output: [], error: [] }
|
35
|
+
Open3.popen3(self[:command]) do |stdin, stdout, stderr, wait_thr|
|
36
|
+
{:output => stdout,:error => stderr}.each do |key, stream|
|
37
|
+
Thread.new do
|
38
|
+
until(raw_line = stream.gets).nil? do
|
39
|
+
output[key] << raw_line
|
40
|
+
puts raw_line if(self[:echo_output])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
wait_thr.join
|
45
|
+
self[:output] = output[:output].join
|
46
|
+
self[:error] = output[:error].join
|
47
|
+
self[:exit_code] = wait_thr.value.to_i
|
26
48
|
end
|
27
|
-
|
28
|
-
|
29
|
-
self[:
|
49
|
+
|
50
|
+
if(self[:debug])
|
51
|
+
puts "command: #{self[:command]}" if(self[:quiet])
|
52
|
+
puts "output: #{self[:output]}"
|
53
|
+
puts "error: #{self[:error]}"
|
54
|
+
puts "exit_code: #{self[:exit_code]}"
|
30
55
|
end
|
31
56
|
|
32
57
|
if((self[:exit_code] != 0) && !self[:ignore_exit_code])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Class
|
69
|
+
description: Class wrapper for system commands
|
70
70
|
email: KCCKSMarshall@gmail.com
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
@@ -74,6 +74,7 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- LICENSE
|
76
76
|
- README.md
|
77
|
+
- lib/IOAdapter.rb
|
77
78
|
- lib/cmd.rb
|
78
79
|
homepage: http://rubygems.org/gems/execute
|
79
80
|
licenses:
|
@@ -98,5 +99,5 @@ rubyforge_project:
|
|
98
99
|
rubygems_version: 2.4.5
|
99
100
|
signing_key:
|
100
101
|
specification_version: 4
|
101
|
-
summary: Class
|
102
|
+
summary: Class wrapper for system commands
|
102
103
|
test_files: []
|