Skip to content

Release v0.2.0

Compare
Choose a tag to compare
@vladimirvivien vladimirvivien released this 06 Nov 20:50
· 11 commits to main since this release
35a3a02

Gexe continues to make progress with this release which includes several major new features including the ability to execute multiple commands, support for command pipes, and introduction of the new http package.

Multiple commands with the exec.CommandBuilder

The exec package now includes type CommandBuilder which provides methods to execute multiple commands using different execution policies including concurrent, pipe, and sequential.

Run commands in sequence

The following exec uses the convenience package function RunAll to execute the specified commands in sequence:

func main() {
    gexe.RunAll(
        'echo "Hello World!"',
        'echo "The time is now:"',
        'date',
    )
}

Run commands concurrently

The following shows the use of convenience function RunConcur, in package exe, to execute the specified commands concurrently:

func main() {
	result := gexe.RunConcur(
		"wget -O /tmp/thenegro.txt https://www.gutenberg.org/cache/epub/15359/pg15359.txt",
		"wget -O /tmp/fleece.txt https://www.gutenberg.org/cache/epub/15265/pg15265.txt",
		"wget -O /tmp/conversation.txt https://www.gutenberg.org/cache/epub/31254/pg31254.txt",
	)

	// inspect result or check for errors.
	if len(result.ErrProcs()) > 0 {
		log.Println("One or more commands failed")
	}
}

Command pipes

The exe.CommandBuilder can be used to pipe commands results from one to the next as is shown in the next example:

func main() {
	pipe := gexe.Pipe(
		"curl https://www.gutenberg.org/cache/epub/15265/pg15265.txt",
		"wc -l",
	)

        // inspect pipe result
	if len(pipe.ErrProcs()) > 0 {
		log.Fatalf("failed to download file")
	}
}

HTTP client support

This release introduces package http which provides an HTTP client API to easily retrieve content from or submit content to a running HTTP server. The following example shows an example of retrieving data from a remote server and saving it to a file.

func main() {
	url := "https://www.gutenberg.org/cache/epub/2148/pg2148.txt"
	if w := gexe.Write("/tmp/eapv2.txt").From(gexe.GetUrl(url).Body()); w.Err() != nil {
		log.Fatal(w.Err())
	}
}

Go to ./examples for all other examples.