command_utils 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_utils.rb +24 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0751ad0ace2f2c6163ce2f9063983bec3a144235
|
4
|
+
data.tar.gz: 4b4d127135dedce36e4797d2ed6afb8520ee8fc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c8b90bacde267555dd47922c3de5e5ec4ccd18076d73e759aacffde9dc50e82b884812c40846dbd24282ff841a1ace9dcabc14d34e5456eb16f5d638d0e8425
|
7
|
+
data.tar.gz: 4fae3852a2c9f830f18cc662100410b4427ea5589e06ff2b4d73fe092dd51463616781b74f0888b93773511ab506e8f0be9dc986cb99f728b3dd3bf67c3a602e
|
data/lib/command_utils.rb
CHANGED
@@ -4,9 +4,10 @@ require_relative 'command_utils/non_zero_status'
|
|
4
4
|
# All methods which execute given command, raise NonZeroStatus if its return is not 0.
|
5
5
|
class CommandUtils
|
6
6
|
|
7
|
-
# Takes command in same format supported by Process#spawn
|
7
|
+
# Takes command in same format supported by Process#spawn.
|
8
8
|
def initialize *command
|
9
9
|
@command = command
|
10
|
+
yield self if block_given?
|
10
11
|
end
|
11
12
|
|
12
13
|
# Execute command, yielding to given block, each time there is output.
|
@@ -34,6 +35,14 @@ class CommandUtils
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
38
|
+
# Takes command in same format supported by Process#spawn.
|
39
|
+
# Execute command, yielding to given block, each time there is output.
|
40
|
+
# stream:: either +:stdout+ or +:stderr+.
|
41
|
+
# data:: data read from respective stream.
|
42
|
+
def self.each_output *command, &block # :yields: stream, data
|
43
|
+
self.new(*command).each_output(&block)
|
44
|
+
end
|
45
|
+
|
37
46
|
# Execute command, logging its output to given Logger object.
|
38
47
|
# Must receive a hash, containing at least:
|
39
48
|
# +:logger+:: Logger instance.
|
@@ -51,6 +60,19 @@ class CommandUtils
|
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
63
|
+
# Takes command in same format supported by Process#spawn.
|
64
|
+
# Execute command, logging its output to given Logger object.
|
65
|
+
# Must receive a hash, containing at least:
|
66
|
+
# +:logger+:: Logger instance.
|
67
|
+
# +:stdout_level+:: Logger level to log stdout.
|
68
|
+
# +:stderr_level+:: Logger level to log stderr.
|
69
|
+
# and optionally:
|
70
|
+
# +:stdout_prefix+:: Prefix to use for all stdout messages.
|
71
|
+
# +:stderr_prefix+:: Prefix to use for all stderr messages.
|
72
|
+
def self.logger_exec command, options
|
73
|
+
self.new(command).logger_exec(options)
|
74
|
+
end
|
75
|
+
|
54
76
|
private
|
55
77
|
|
56
78
|
def run
|
@@ -83,4 +105,4 @@ class CommandUtils
|
|
83
105
|
)
|
84
106
|
end
|
85
107
|
end
|
86
|
-
end
|
108
|
+
end
|