示例#1
0
文件: sh_test.go 项目: simudream/sh-2
func ExamplePipeWith() {
	upper := sh.Cmd("tr", "[:lower:]", "[:upper:]")
	grep := sh.Cmd("grep")

	fmt.Print(sh.PipeWith(SWCrawl, grep("far"), upper()))
	// output:
	// A LONG TIME AGO, IN A GALAXY FAR, FAR AWAY....
}
示例#2
0
文件: sh_test.go 项目: simudream/sh-2
func ExamplePipe() {
	echo := sh.Cmd("echo")

	// note, you can "bake in" arguments when you create these functions.
	upper := sh.Cmd("tr", "[:lower:]", "[:upper:]")
	grep := sh.Cmd("grep")

	// Equivalent of shell command:
	// $ echo Hi there! | grep -o Hi | wc -w
	fmt.Print(sh.Pipe(echo(SWCrawl), grep("far"), upper()))
	// output:
	// A LONG TIME AGO, IN A GALAXY FAR, FAR AWAY....
}
示例#3
0
文件: sh_test.go 项目: simudream/sh-2
func ExampleCmd() {
	echo := sh.Cmd("echo")

	fmt.Print(echo("Hi there!"))
	// output:
	// Hi there!
}
示例#4
0
文件: sh_test.go 项目: simudream/sh-2
func TestString(t *testing.T) {
	ex := sh.Cmd("thiswontwork")()
	s := ex.String()
	expected := "exec: \"thiswontwork\": executable file not found in $PATH"
	if s != expected {
		t.Errorf("expected %q, got %q", expected, s)
	}
}
示例#5
0
文件: sh_test.go 项目: simudream/sh-2
func ExampleRead() {
	grep := sh.Cmd("grep")

	name := "ExampleReadTest"
	f, cleanup := openTempFile(name, SWCrawl)
	defer cleanup()

	fmt.Print(sh.Pipe(sh.Read(f), grep("far")))
	// output:
	// A long time ago, in a galaxy far, far away....
}
示例#6
0
文件: sh_test.go 项目: simudream/sh-2
func ExampleDump() {
	grep := sh.Cmd("grep")

	name := "ExampleDumpTest"
	defer writeTempFile(name, SWCrawl)()

	// Equivalent of shell command
	// $ cat ExampleDumpTest | grep far
	fmt.Print(sh.Pipe(sh.Dump(name), grep("far")))
	// output:
	// A long time ago, in a galaxy far, far away....
}
示例#7
0
文件: sh_test.go 项目: simudream/sh-2
func Example_String() {
	echo := sh.Cmd("echo")

	executable := echo("Hi there!")

	// Since we're passing the output into a function expecting a string, we
	// have to call String() on the output of the command.
	var s string = executable.String()
	fmt.Print(s)
	// output:
	// Hi there!
}