convert repo plugin to golang

This commit is contained in:
Michael Hobbs
2017-01-03 22:27:20 -08:00
parent 8d83803763
commit b6dffaabee
44 changed files with 2705 additions and 24 deletions

View 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()
}

View File

@@ -0,0 +1,7 @@
package main
import "github.com/codeskyblue/go-sh"
func main() {
sh.Command("less", "less.go").Run()
}

View 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()
}

View 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)
}