Example #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:
}
Example #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)
}
Example #3
0
func ExampleCommand() {
	stream.Run(
		stream.Numbers(1, 100),
		stream.Command("wc", "-l"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 100
}
Example #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
}
Example #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
}
Example #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
}
Example #7
0
// ListMachines returns a list of machine names.
func ListMachines() ([]string, error) {
	return stream.Contents(stream.Command(dockerMachineBinary, "ls", "-q"))
}
Example #8
0
func BenchmarkCmd(b *testing.B) {
	stream.Run(
		stream.Repeat("hello", b.N),
		stream.Command("cat"),
	)
}