kommando 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/bin/release +1 -1
- data/bin/stress +1 -0
- data/examples/in_shell.rb +16 -0
- data/examples/nano.rb +2 -0
- data/examples/nano_match.rb +24 -0
- data/examples/stderr_to_out.rb +7 -0
- data/kommando.gemspec +1 -0
- data/lib/kommando.rb +26 -1
- data/lib/kommando/buffer.rb +6 -0
- data/lib/kommando/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f31bfc50087990d25272c5bb0bd2d45967dfb70
|
4
|
+
data.tar.gz: 8ee8d780d34cc47e500bcb0479d7d9e80934c65b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b6b2dc55fcbfbe5c95e270d7ce48424eaf1e6a46b57c7f002c3cda1fc51e3858e93f9f866fcd6801f134f0247e395551ce9b0b7cfb34dbecc8872bd06eaee7
|
7
|
+
data.tar.gz: 526e8c68a2543d69422d22904ccb3561dcddfbeefa4a64a45f0b9566caf045183a1c80d41e4e84bc98f60ff6fac7c00fe21f72f322831407637b9d2be8edeccf
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/bin/release
CHANGED
data/bin/stress
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "./lib/kommando"
|
2
|
+
|
3
|
+
k = Kommando.new "$ printf 'name: '; read N; printf \"lol, $N\n\"", {
|
4
|
+
output: true
|
5
|
+
}
|
6
|
+
|
7
|
+
k.out.on "name: " do
|
8
|
+
k.out.on /^lol, [^\n]+\r\n/ do
|
9
|
+
puts "Matched 'lol, USERINPUT\\r\\n' on stdout"
|
10
|
+
end
|
11
|
+
|
12
|
+
k.in << "hello\n"
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
k.run
|
data/examples/nano.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "./lib/kommando"
|
2
|
+
require "tempfile"
|
3
|
+
|
4
|
+
scratch = Tempfile.new
|
5
|
+
|
6
|
+
k = Kommando.new "nano scratch.path", {
|
7
|
+
output: true
|
8
|
+
}
|
9
|
+
k.out.on "GNU nano" do
|
10
|
+
k.in << "hello\r"
|
11
|
+
k.in << "\x1B\x1Bx"
|
12
|
+
|
13
|
+
k.out.on "Save modified buffer" do
|
14
|
+
k.in << "y"
|
15
|
+
|
16
|
+
k.out.on "File Name to Write" do
|
17
|
+
k.in << "\r"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
k.run
|
23
|
+
|
24
|
+
`reset` #TODO: reset in kommando
|
data/kommando.gemspec
CHANGED
data/lib/kommando.rb
CHANGED
@@ -36,6 +36,9 @@ class Kommando
|
|
36
36
|
@pid = nil
|
37
37
|
|
38
38
|
@shell = false
|
39
|
+
|
40
|
+
@matchers = {}
|
41
|
+
@matcher_buffer = ""
|
39
42
|
end
|
40
43
|
|
41
44
|
def run_async
|
@@ -130,16 +133,30 @@ class Kommando
|
|
130
133
|
@stdout.append c if c
|
131
134
|
print c if @output_stdout
|
132
135
|
stdout_file.write c if @output_file
|
136
|
+
|
137
|
+
if c
|
138
|
+
@matcher_buffer << c
|
139
|
+
|
140
|
+
matchers_copy = @matchers.clone # blocks can insert to @matchers while iteration is undergoing
|
141
|
+
matchers_copy.each_pair do |matcher,block|
|
142
|
+
if @matcher_buffer.match matcher
|
143
|
+
block.call
|
144
|
+
@matchers.delete matcher # do not match again TODO: is this safe?
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
133
148
|
end
|
134
149
|
end
|
135
150
|
|
136
151
|
thread_stdin = Thread.new do
|
152
|
+
sleep 0.1 # allow program to start, do not write "in terminal"
|
137
153
|
while true do
|
138
154
|
c = @stdin.getc
|
139
155
|
unless c
|
140
156
|
sleep 0.01
|
141
157
|
next
|
142
158
|
end
|
159
|
+
|
143
160
|
stdin.write c
|
144
161
|
end
|
145
162
|
end
|
@@ -188,11 +205,19 @@ class Kommando
|
|
188
205
|
end
|
189
206
|
|
190
207
|
def out
|
191
|
-
if @shell
|
208
|
+
string = if @shell
|
192
209
|
@stdout.to_s.strip
|
193
210
|
else
|
194
211
|
@stdout.to_s
|
195
212
|
end
|
213
|
+
|
214
|
+
kommando = self
|
215
|
+
string.define_singleton_method(:on) do |matcher, &block|
|
216
|
+
matchers = kommando.instance_variable_get(:@matchers)
|
217
|
+
matchers[matcher] = block
|
218
|
+
end
|
219
|
+
|
220
|
+
string
|
196
221
|
end
|
197
222
|
|
198
223
|
def code
|
data/lib/kommando/buffer.rb
CHANGED
@@ -2,6 +2,8 @@ class Kommando::Buffer
|
|
2
2
|
|
3
3
|
def initialize
|
4
4
|
@buffer = []
|
5
|
+
|
6
|
+
@matchers = {}
|
5
7
|
end
|
6
8
|
|
7
9
|
def append(string)
|
@@ -19,4 +21,8 @@ class Kommando::Buffer
|
|
19
21
|
def getc
|
20
22
|
@buffer.shift
|
21
23
|
end
|
24
|
+
|
25
|
+
def on(matcher, &block)
|
26
|
+
@matchers[matcher] = block
|
27
|
+
end
|
22
28
|
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.12
|
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-
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '4.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Great for integration testing.
|
84
98
|
email:
|
85
99
|
- matti.paksula@iki.fi
|
@@ -108,11 +122,14 @@ files:
|
|
108
122
|
- examples/env.rb
|
109
123
|
- examples/exit.rb
|
110
124
|
- examples/in.rb
|
125
|
+
- examples/in_shell.rb
|
111
126
|
- examples/kill.rb
|
112
127
|
- examples/live_output.rb
|
113
128
|
- examples/nano.rb
|
129
|
+
- examples/nano_match.rb
|
114
130
|
- examples/ping.rb
|
115
131
|
- examples/shell.rb
|
132
|
+
- examples/stderr_to_out.rb
|
116
133
|
- examples/stdout_to_file.rb
|
117
134
|
- examples/timeout.rb
|
118
135
|
- examples/uptime.rb
|