Пример #1
0
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
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
func ExampleCmd() {
	echo := sh.Cmd("echo")

	fmt.Print(echo("Hi there!"))
	// output:
	// Hi there!
}
Пример #4
0
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
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
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
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!
}