kommando 0.0.12 → 0.0.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f31bfc50087990d25272c5bb0bd2d45967dfb70
4
- data.tar.gz: 8ee8d780d34cc47e500bcb0479d7d9e80934c65b
3
+ metadata.gz: a4c723b5a14a2c459faa1541baf8191bd3d5e085
4
+ data.tar.gz: 933819bd35d6494959f5a3d1fd4d4fc871ba60c4
5
5
  SHA512:
6
- metadata.gz: a4b6b2dc55fcbfbe5c95e270d7ce48424eaf1e6a46b57c7f002c3cda1fc51e3858e93f9f866fcd6801f134f0247e395551ce9b0b7cfb34dbecc8872bd06eaee7
7
- data.tar.gz: 526e8c68a2543d69422d22904ccb3561dcddfbeefa4a64a45f0b9566caf045183a1c80d41e4e84bc98f60ff6fac7c00fe21f72f322831407637b9d2be8edeccf
6
+ metadata.gz: 8bae101165bffb3ebc49ace448bd297a5139f8d4265911d8283aa7dadd9db08277fade2934a03a618220eacf6398a5266ee0f94764e22b3a872fc4a311376821
7
+ data.tar.gz: 7e0a9e250d0979fb94ca4c4ef1331a3115056b414f358346a17c5ab9cfb49bf78439796c4f6ca80c3a5ff16b238b4c67a28789f86cec188ab34c45f8d1cab0a9
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.13
4
+ Shorthands for run and run_async, blocking until completed.
5
+
6
+ - FEAT: Immediate run with `Kommando.run "uptime", {}`
7
+ - FEAT: Immediate run_async with `Kommando.run_async "uptime", {}`
8
+ - FEAT: Block until command completes with `k.wait`
9
+ - EXAMPLES: `shorthands.rb` and `wait.rb`
10
+
3
11
  ## 0.0.12
4
12
  Support for matching out and running code on match.
5
13
 
@@ -1,8 +1,6 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "sleep 0.5"
4
- k.run_async
5
-
3
+ k = Kommando.run_async "sleep 0.5"
6
4
  puts "started in background"
7
5
 
8
6
  while (k.code == nil) do
@@ -1,12 +1,11 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "$ echo $KOMMANDO_ENV1 $KOMMANDO_ENV2", {
3
+ k = Kommando.run "$ echo $KOMMANDO_ENV1 $KOMMANDO_ENV2", {
4
4
  env: {
5
5
  KOMMANDO_ENV1: "hello",
6
6
  KOMMANDO_ENV2: "world"
7
7
  }
8
8
  }
9
- k.run
10
9
 
11
10
  raise "err" unless k.out == "hello world"
12
11
  puts k.out
@@ -1,11 +1,9 @@
1
1
  require "./lib/kommando"
2
2
 
3
- failure = Kommando.new "false"
4
- failure.run
3
+ failure = Kommando.run "false"
5
4
 
6
5
  puts "Failure error: #{failure.code}"
7
6
 
8
- success = Kommando.new "true"
9
- success.run
7
+ success = Kommando.run "true"
10
8
 
11
9
  puts "Success error: #{success.code}"
@@ -1,14 +1,10 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "sleep 10"
4
-
5
- Thread.new do
6
- puts "killer is waiting.."
7
- sleep 1
8
- k.kill
9
- puts "..killed."
10
- end
11
- k.run
3
+ k = Kommando.run_async "sleep 10"
4
+
5
+ sleep 1
6
+ k.kill
7
+ puts "..killed."
12
8
 
13
9
  raise "not 137" unless k.code == 137
14
10
 
@@ -1,7 +1,5 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "ping -c 3 127.0.0.1", {
3
+ Kommando.run "ping -c 3 127.0.0.1", {
4
4
  output: true
5
5
  }
6
-
7
- k.run
@@ -3,7 +3,7 @@ require "tempfile"
3
3
 
4
4
  scratch = Tempfile.new
5
5
 
6
- k = Kommando.new "nano scratch.path", {
6
+ k = Kommando.new "nano #{scratch.path}", {
7
7
  output: true
8
8
  }
9
9
  k.out.on "GNU nano" do
@@ -1,6 +1,4 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "ping -c 3 google.com"
4
- k.run
5
-
3
+ k = Kommando.run "ping -c 3 google.com"
6
4
  puts k.out
@@ -1,7 +1,6 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "$ echo 'hello\nworld' | rev | rev"
4
- k.run
3
+ k = Kommando.run "$ echo 'hello\nworld' | rev | rev"
5
4
 
6
5
  raise "err" unless k.out == "hello\r\nworld"
7
6
  puts "shell says: #{k.out}"
@@ -0,0 +1,13 @@
1
+ require "./lib/kommando"
2
+
3
+ k = Kommando.run "$ echo hello"
4
+ raise "err" unless k.out == "hello"
5
+
6
+ puts k.out
7
+
8
+ k = Kommando.run_async "$ echo hello"
9
+ k.wait
10
+
11
+ raise "err" unless k.out == "hello"
12
+
13
+ puts k.out
@@ -1,7 +1,6 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "$ (>&2 echo 'err'); echo 'out'"
4
- k.run
3
+ k = Kommando.run "$ (>&2 echo 'err'); echo 'out'"
5
4
 
6
5
  raise "err" unless k.out == "err\r\nout"
7
6
  puts k.out
@@ -1,10 +1,10 @@
1
1
  require "./lib/kommando"
2
2
 
3
3
  k = Kommando.new "sleep 2", {
4
- timeout: 1
4
+ timeout: 0.5
5
5
  }
6
6
  k2 = Kommando.new "sleep 2", {
7
- timeout: 1
7
+ timeout: 0.5
8
8
  }
9
9
 
10
10
  k.run
@@ -1,6 +1,5 @@
1
1
  require "./lib/kommando"
2
2
 
3
- k = Kommando.new "uptime"
4
- k.run
3
+ k = Kommando.run "uptime"
5
4
 
6
5
  puts k.out
@@ -0,0 +1,6 @@
1
+ require "./lib/kommando"
2
+
3
+ k = Kommando.run_async "sleep 0.5"
4
+ raise "err" if k.code
5
+ k.wait
6
+ raise "err" unless k.code == 0
@@ -6,6 +6,19 @@ require_relative "kommando/version"
6
6
  require_relative "kommando/buffer"
7
7
 
8
8
  class Kommando
9
+ class << self
10
+ def run(cmd, opts={})
11
+ k = Kommando.new cmd, opts
12
+ k.run
13
+ k
14
+ end
15
+
16
+ def run_async(cmd, opts={})
17
+ k = Kommando.new cmd, opts
18
+ k.run_async
19
+ k
20
+ end
21
+ end
9
22
 
10
23
  def initialize(cmd, opts={})
11
24
  @cmd = cmd
@@ -227,4 +240,8 @@ class Kommando
227
240
  def in
228
241
  @stdin
229
242
  end
243
+
244
+ def wait
245
+ sleep 0.001 until @code
246
+ end
230
247
  end
@@ -1,3 +1,3 @@
1
1
  class Kommando
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kommando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
@@ -129,10 +129,12 @@ files:
129
129
  - examples/nano_match.rb
130
130
  - examples/ping.rb
131
131
  - examples/shell.rb
132
+ - examples/shorthands.rb
132
133
  - examples/stderr_to_out.rb
133
134
  - examples/stdout_to_file.rb
134
135
  - examples/timeout.rb
135
136
  - examples/uptime.rb
137
+ - examples/wait.rb
136
138
  - kommando.gemspec
137
139
  - lib/kommando.rb
138
140
  - lib/kommando/buffer.rb