示例#1
0
func ExampleCommand_withError() {
	err := stream.Run(stream.Command("no_such_command"))
	if err == nil {
		fmt.Println("execution of missing command succeeded unexpectedly")
	}
	// Output:
}
示例#2
0
// GetHostConfig gets the machine config from docker-machine.
// It takes an initialized driver.HostConfig struct with the Driver
// field initialized to the driver-specific type.
// The passed-in object is filled in with the contents of the config.
func GetHostConfig(name string, config *drivers.HostConfig) error {
	contents, err := stream.Contents(stream.Command(dockerMachineBinary, "inspect", name))
	if err != nil {
		return err
	}

	return json.Unmarshal([]byte(strings.Join(contents, "\n")), config)
}
示例#3
0
func ExampleCommand() {
	stream.Run(
		stream.Numbers(1, 100),
		stream.Command("wc", "-l"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 100
}
示例#4
0
// GetDockerFlags returns the list of flags we need to pass to docker to
// talk to the given machine's docker daemon.
// We expect a single line, but then split that line into individual flags.
func GetDockerFlags(name string) ([]string, error) {
	contents, err := stream.Contents(stream.Command(dockerMachineBinary, "config", name))
	if err != nil {
		return nil, err
	}

	if len(contents) != 1 {
		return nil, util.Errorf("expected a single output line, got: %v", contents)
	}
	return strings.Split(contents[0], " "), nil
}
示例#5
0
func ExampleXargs_splitArguments() {
	// Xargs should split the long list of arguments into
	// three executions to keep command length below 4096.
	stream.Run(
		stream.Numbers(1, 2000),
		stream.Xargs("echo"),
		stream.Command("wc", "-l"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 3
}
示例#6
0
func ExampleCommand_outputOnly() {
	stream.Run(
		stream.Command("find", ".", "-type", "f", "-print"),
		stream.Grep(`^\./stream.*\.go$`),
		stream.Sort(),
		stream.WriteLines(os.Stdout),
	)

	// Output:
	// ./stream.go
	// ./stream_test.go
}
示例#7
0
// ListMachines returns a list of machine names.
func ListMachines() ([]string, error) {
	return stream.Contents(stream.Command(dockerMachineBinary, "ls", "-q"))
}
示例#8
0
func BenchmarkCmd(b *testing.B) {
	stream.Run(
		stream.Repeat("hello", b.N),
		stream.Command("cat"),
	)
}