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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4c723b5a14a2c459faa1541baf8191bd3d5e085
4
- data.tar.gz: 933819bd35d6494959f5a3d1fd4d4fc871ba60c4
3
+ metadata.gz: 96fe9669f6508544674dd94b73b3b8c9cf34ae8f
4
+ data.tar.gz: 9a58c3f6946f95ac9edf60d55a2cdf47e15fdd40
5
5
  SHA512:
6
- metadata.gz: 8bae101165bffb3ebc49ace448bd297a5139f8d4265911d8283aa7dadd9db08277fade2934a03a618220eacf6398a5266ee0f94764e22b3a872fc4a311376821
7
- data.tar.gz: 7e0a9e250d0979fb94ca4c4ef1331a3115056b414f358346a17c5ab9cfb49bf78439796c4f6ca80c3a5ff16b238b4c67a28789f86cec188ab34c45f8d1cab0a9
6
+ metadata.gz: 50c8bd2ffb7986a0ee4c3abf75ef39b650e035e506d475930d6ec81da4a06fa90378cf9f9ecd4bd9c7a42a6c27962ec0ab8df24b0a0450de260bd2cd8aa1b7dc
7
+ data.tar.gz: a52c9187140f7964d8f0f6e6dba3191f78dc95b6984d07d056b3268a3beb08926d770eccb27d7b0e9e4fdec37373b17257f5c5346f09a974947159cf08bc7531
@@ -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
 
@@ -1,9 +1,17 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.run_async "sleep 0.5"
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
- while (k.code == nil) do
13
+
14
+ until (exited) do
7
15
  print "."
8
16
  sleep 0.1
9
17
  end
@@ -10,4 +10,4 @@ k.wait
10
10
 
11
11
  raise "err" unless k.out == "hello"
12
12
 
13
- puts k.out
13
+ Kommando.puts "$ echo ok"
@@ -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
@@ -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"
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Kommando
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.15"
3
3
  end
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.13
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-10 00:00:00.000000000 Z
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