-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (34 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"strings"
"syscall"
"github.com/matti/gommando"
)
func main() {
g := gommando.New("ping google.com")
g.Output(true)
g.Stdout().Once(func(haystack string) bool {
return strings.Index(haystack, "google") > 0
}).Then(func(s string) {
println(" found 'google', I'll never say this again because I'm after .Once, but I'll trigger the next...")
}).Then(func(s string) {
println(" ... .Then and I'll trigger the next .Once which will start to match now:")
}).Once(func(haystack string) bool {
return strings.Index(haystack, "ttl") > 0
}).Then(func(s string) {
println(" found 'ttl' and I'll never say this again because I'm after .Once")
})
g.Stdout().Once(func(haystack string) bool {
return strings.Index(haystack, "seq=3") > 0
}).Then(func(s string) {
println(" 3 pings sent, exiting")
g.Signal(syscall.SIGTERM)
g.Wait()
})
g.Stdout().Every(func(haystack string) bool {
return strings.Index(haystack, "seq=") > 0
}).Then(func(s string) {
println(" found 'seq=' seen and I continue to say this because I'm after .Every")
})
g.Run()
}