kommando 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/examples/async.rb +10 -2
- data/examples/shorthands.rb +1 -1
- data/examples/timeout.rb +10 -0
- data/examples/when.rb +32 -0
- data/lib/kommando.rb +34 -0
- data/lib/kommando/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: 96fe9669f6508544674dd94b73b3b8c9cf34ae8f
|
4
|
+
data.tar.gz: 9a58c3f6946f95ac9edf60d55a2cdf47e15fdd40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50c8bd2ffb7986a0ee4c3abf75ef39b650e035e506d475930d6ec81da4a06fa90378cf9f9ecd4bd9c7a42a6c27962ec0ab8df24b0a0450de260bd2cd8aa1b7dc
|
7
|
+
data.tar.gz: a52c9187140f7964d8f0f6e6dba3191f78dc95b6984d07d056b3268a3beb08926d770eccb27d7b0e9e4fdec37373b17257f5c5346f09a974947159cf08bc7531
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.0.15
|
4
|
+
Exit and timeout callbacks, output shorthand.
|
5
|
+
|
6
|
+
- FEAT: Shorthand `Kommando.puts "uptime"`
|
7
|
+
- FEAT: Callback `k.when :exit block`
|
8
|
+
- FEAT: Callback `k.when :timeout block`
|
9
|
+
- EXAMPLES: `async.rb`
|
10
|
+
|
11
|
+
## 0.0.14
|
12
|
+
When callbacks
|
13
|
+
|
14
|
+
- FEAT: Callback `k.when "start" block`
|
15
|
+
- EXAMPLES: `when.rb`
|
16
|
+
|
3
17
|
## 0.0.13
|
4
18
|
Shorthands for run and run_async, blocking until completed.
|
5
19
|
|
data/examples/async.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require "./lib/kommando"
|
2
2
|
|
3
|
-
k = Kommando.
|
3
|
+
k = Kommando.new "sleep 1"
|
4
|
+
|
5
|
+
exited = false
|
6
|
+
k.when "exit" do
|
7
|
+
exited = true
|
8
|
+
end
|
9
|
+
|
10
|
+
k.run_async
|
4
11
|
puts "started in background"
|
5
12
|
|
6
|
-
|
13
|
+
|
14
|
+
until (exited) do
|
7
15
|
print "."
|
8
16
|
sleep 0.1
|
9
17
|
end
|
data/examples/shorthands.rb
CHANGED
data/examples/timeout.rb
CHANGED
@@ -7,9 +7,19 @@ k2 = Kommando.new "sleep 2", {
|
|
7
7
|
timeout: 0.5
|
8
8
|
}
|
9
9
|
|
10
|
+
did_run_timeout_callback = false
|
11
|
+
|
12
|
+
k.when :timeout do
|
13
|
+
did_run_timeout_callback = true
|
14
|
+
end
|
15
|
+
|
10
16
|
k.run
|
11
17
|
k2.run
|
12
18
|
|
13
19
|
if k.code == 1 && k2.code == 1
|
14
20
|
puts "timed out"
|
21
|
+
else
|
22
|
+
raise "code not 1"
|
15
23
|
end
|
24
|
+
|
25
|
+
raise "timeout callback not called" unless did_run_timeout_callback
|
data/examples/when.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "./lib/kommando"
|
2
|
+
|
3
|
+
k = Kommando.new "$ echo hello"
|
4
|
+
ended = false
|
5
|
+
got_start = false
|
6
|
+
got_exit = false
|
7
|
+
got_start_when_given_as_symbol = false
|
8
|
+
|
9
|
+
k.when "start" do
|
10
|
+
got_start = true
|
11
|
+
puts "start!"
|
12
|
+
raise "code in start" if k.code
|
13
|
+
raise "ended in start" if ended
|
14
|
+
end
|
15
|
+
|
16
|
+
k.when :start do
|
17
|
+
puts ":start!"
|
18
|
+
got_start_when_given_as_symbol = true
|
19
|
+
end
|
20
|
+
|
21
|
+
k.when :exit do
|
22
|
+
got_exit = true
|
23
|
+
end
|
24
|
+
|
25
|
+
k.run
|
26
|
+
ended = true
|
27
|
+
|
28
|
+
raise "got_start not set" unless got_start
|
29
|
+
raise "got_start_when_given_as_symbol not set" unless got_start_when_given_as_symbol
|
30
|
+
raise "got_exit not set" unless got_exit
|
31
|
+
|
32
|
+
puts "end"
|
data/lib/kommando.rb
CHANGED
@@ -18,6 +18,12 @@ class Kommando
|
|
18
18
|
k.run_async
|
19
19
|
k
|
20
20
|
end
|
21
|
+
|
22
|
+
def puts(cmd, opts={})
|
23
|
+
k = Kommando.new cmd, opts
|
24
|
+
k.run
|
25
|
+
Kernel.puts k.out
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
29
|
def initialize(cmd, opts={})
|
@@ -52,6 +58,8 @@ class Kommando
|
|
52
58
|
|
53
59
|
@matchers = {}
|
54
60
|
@matcher_buffer = ""
|
61
|
+
|
62
|
+
@whens = {}
|
55
63
|
end
|
56
64
|
|
57
65
|
def run_async
|
@@ -174,6 +182,12 @@ class Kommando
|
|
174
182
|
end
|
175
183
|
end
|
176
184
|
|
185
|
+
if @whens[:start]
|
186
|
+
@whens[:start].each do |block|
|
187
|
+
block.call
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
177
191
|
if @timeout
|
178
192
|
begin
|
179
193
|
Timeout.timeout(@timeout) do
|
@@ -214,6 +228,18 @@ class Kommando
|
|
214
228
|
raise Kommando::Error, "Command '#{command}' not found"
|
215
229
|
end
|
216
230
|
|
231
|
+
if @whens[:timeout]
|
232
|
+
@whens[:timeout].each do |block|
|
233
|
+
block.call
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
if @whens[:exit]
|
238
|
+
@whens[:exit].each do |block|
|
239
|
+
block.call
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
217
243
|
true
|
218
244
|
end
|
219
245
|
|
@@ -244,4 +270,12 @@ class Kommando
|
|
244
270
|
def wait
|
245
271
|
sleep 0.001 until @code
|
246
272
|
end
|
273
|
+
|
274
|
+
def when(event, &block)
|
275
|
+
@whens[event.to_sym] = if @whens[event.to_sym]
|
276
|
+
@whens[event.to_sym] << block
|
277
|
+
else
|
278
|
+
[block]
|
279
|
+
end
|
280
|
+
end
|
247
281
|
end
|
data/lib/kommando/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kommando
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- examples/timeout.rb
|
136
136
|
- examples/uptime.rb
|
137
137
|
- examples/wait.rb
|
138
|
+
- examples/when.rb
|
138
139
|
- kommando.gemspec
|
139
140
|
- lib/kommando.rb
|
140
141
|
- lib/kommando/buffer.rb
|