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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/command_utils.rb +24 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55fdf974b8fe587df928b134b85230d1e2444658
4
- data.tar.gz: 0972d50cb9c28dddfbf24e1fe2af7fd91efe716e
3
+ metadata.gz: 0751ad0ace2f2c6163ce2f9063983bec3a144235
4
+ data.tar.gz: 4b4d127135dedce36e4797d2ed6afb8520ee8fc9
5
5
  SHA512:
6
- metadata.gz: 1cf38a61eea8bc39a2a4a229f90e74642e3d6022514215ec7d0093f70cb1761299a5ca901b4ae0af46954afa05bdda0c940003d561c5c2c611123df535050095
7
- data.tar.gz: 74ed7398ded2e1cc63041a832ccdb9d7ecefd2a230a0a04921095ec38028c518b50181339744a72a253a816ae79a69bbbb8acdb989f21d99514ce26211976fe7
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Pugliese Ornellas