convert repo plugin to golang
This commit is contained in:
41
plugins/common/vendor/github.com/codeskyblue/go-sh/example/example1.go
generated
vendored
Normal file
41
plugins/common/vendor/github.com/codeskyblue/go-sh/example/example1.go
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/codeskyblue/go-sh"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sh.Command("echo", "hello").Run()
|
||||
out, err := sh.Command("echo", "hello").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("output is", string(out))
|
||||
|
||||
var a int
|
||||
sh.Command("echo", "2").UnmarshalJSON(&a)
|
||||
fmt.Println("a =", a)
|
||||
|
||||
s := sh.NewSession()
|
||||
s.Alias("hi", "echo", "hi")
|
||||
s.Command("hi", "boy").Run()
|
||||
|
||||
fmt.Print("pwd = ")
|
||||
s.Command("pwd", sh.Dir("/")).Run()
|
||||
|
||||
if !sh.Test("dir", "data") {
|
||||
sh.Command("echo", "mkdir", "data").Run()
|
||||
}
|
||||
|
||||
sh.Command("echo", "hello", "world").
|
||||
Command("awk", `{print "second arg is "$2}`).Run()
|
||||
s.ShowCMD = true
|
||||
s.Command("echo", "hello", "world").
|
||||
Command("awk", `{print "second arg is "$2}`).Run()
|
||||
|
||||
s.SetEnv("BUILD_ID", "123").Command("bash", "-c", "echo $BUILD_ID").Run()
|
||||
s.Command("bash", "-c", "echo current shell is $SHELL").Run()
|
||||
}
|
||||
7
plugins/common/vendor/github.com/codeskyblue/go-sh/example/less/less.go
generated
vendored
Normal file
7
plugins/common/vendor/github.com/codeskyblue/go-sh/example/less/less.go
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/codeskyblue/go-sh"
|
||||
|
||||
func main() {
|
||||
sh.Command("less", "less.go").Run()
|
||||
}
|
||||
17
plugins/common/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go
generated
vendored
Normal file
17
plugins/common/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/codeskyblue/go-sh"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
fmt.Println("Usage: PROGRAM <file>")
|
||||
return
|
||||
}
|
||||
sh.Command("tail", "-f", flag.Arg(0)).Run()
|
||||
}
|
||||
23
plugins/common/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go
generated
vendored
Normal file
23
plugins/common/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sh "github.com/codeskyblue/go-sh"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := sh.Command("sleep", "3")
|
||||
c.Start()
|
||||
err := c.WaitTimeout(time.Second * 1)
|
||||
if err != nil {
|
||||
fmt.Printf("timeout should happend: %v\n", err)
|
||||
}
|
||||
// timeout should be a session
|
||||
out, err := sh.Command("sleep", "2").SetTimeout(time.Second).Output()
|
||||
fmt.Printf("output:(%s), err(%v)\n", string(out), err)
|
||||
|
||||
out, err = sh.Command("echo", "hello").SetTimeout(time.Second).Output()
|
||||
fmt.Printf("output:(%s), err(%v)\n", string(out), err)
|
||||
}
|
||||
Reference in New Issue
Block a user