Releases: vladimirvivien/gexe
v0.4.1
What's Changed
- Updates to CI and CI configurations by @cpanato in #55
- Fixes to example docs by @vladimirvivien in #58
- Ability to specify userid/groupid for process execution by @vladimirvivien in #59
- Ability to set working directory for commands by @vladimirvivien in #61
- Support for context-awareness to gexe packages by @vladimirvivien in #63
New Contributors
Full Changelog: v0.4.0...v0.4.1
v0.4.0
This release did not introduce new functionalities, but rather implemented fixes and improvements that have been lingering for a while.
Release overview
- Better support for setting Stdout/Stderr when working with
exec
package - Fixed out-of-order bug that would make
exec.Proc.Resut()
andexec.Proc.Out()
calls return empty result from the process - Additional checked error propagation in API call chain in several packages
- Enhancements to
exec.CommandBuilder
to fix piped commands constructs - Ability to set stdout/stderr for batch commands with exec.CommandBuilder
- Further standardization of function and method signatures for packages
http
andfs
- Enhancements to internal tests
API changes
Package exec
changes
Previously, method Proc.Out()
in package exec
would automatically start a defined process (if not started) then return output of the process as a combined Stdout/Stderr streams. This behavior has been simplified:
- The API user is responsible for starting the process prior to calling
proc.Out()
- Method
Proc.Out()
only returns the combined output stream if no other streams were set for the process - If other streams were set, an API user is responsible for accessing the configured output stream for process result.
Method proc.Result()
still returns the combined output stream as string
(by calling proc.Out()
) if an output stream was not explicitly set.
See example here
Package vars
changes
This release introduces subtle changes to how methods vars.Variables.Envs
and vars.Variables.Vars
work. Before this release, these methods accepted a single string with key=value
pairs separated by spaces:
gexe.Vars(`msg0=hello msg1=world`).
In this release, however, the signatures for both Envs
and Vars
have been updated as variadic methods that accept zero or more string values. Each string parameter is not expected to provide a single key=value
pair:
gexe.Envs(`GOOS="linux"`, `GOARCH=arm64`).Run(`go build .`)
Note that this change provides the flexibility of specifying variables with quoted values and supports spaces in the values.
Related PRs
- Functionality improvements by @vladimirvivien in #53
- Lock contention fix by @vladimirvivien in #54
v0.3.0
What's Changed
Improvement of session variables
Now all types (existing and new ones) allows an injection of value of type vars.Variables
to allow tracking and use of variables during a gexe
session. The following shows an example of process being launched with variables:
variables := vars.New().SetVar("proc", "echo")
exec.RunProcWithVars(`$proc "Hello World!"`, variables)
In the majority of cases, you will start the API chain from the gexe
package which has a default instance of vars.Variables
ready to use as shown below:
gexe.SetVar("proc", "echo")
gexe.Run(`$proc "Hello World!")
Extending the fs
package
The fs
package has been extended to introduce types and methods to work with OS directory paths. In addition to working with files, the new fs.Path
allows the followings:
- Query path information
- Creation of directory at a specified path point
- Removal of resources at specified path
Improvements to package http
In this release, package http
has been updated to use an API similar to that of fs (for file reading/writing). Using the new API makes it easy to retrieve resources from an HTTP server and output it in different types including string, bytes, io.Reader, etc. The same changes has been done to write data to a remote web server.
Example:
gexe.FileWrite("/tmp/eapv2.txt").String(gexe.GetUrl(`https://remote/file`).String())
PR list
- See PR General improvements for project by @vladimirvivien in #51
- Update project documentation by @vladimirvivien in #52
Full Changelog: v0.2.0...v0.3.0
Release v0.2.0
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.
v0.1.1
v0.1.1
This release focuses on code stability and tidiness. It also introduces the exec/CommandBuilder
type which is used to execute batches of commands using several execution strategy including:
- Execution in serial
- Execution concurrently
- Exit on error
- Continue on error
Example
cmds := exec.Commands("git commit --signoff", "history", "man time", "man man")
cmds.WithPolicy(exec.CmdOnErrContinue).Run()
v0.1.0
v0.1.0
This is the first non-alpha release of project gexe. The goal of project gexe is to make it dead simple to write code that interacts with the OS (and/or other components) with the type safety of the Go programming language.
What does it do ?
- Parse and execute OS comands provided as plain and clear text as you would in a shell.
- Support for variable expansion in command string (i.e.
gexe.Run("echo $HOME")
) - Get process information (i.e. PID, status, exit code, etc)
- Stream data from stdout while process is executing
- Get program information (i.e. args, binary name, working dir, etc)
- Easily read file content into different targets (string, bytes, io.Writer, etc)
- Easily write file content from different sources (i.e. string, bytes, io.Reader, etc)
- Integrate with your shell script using
go run
Example
Here is a simple example of how gexe can be used build Go binary for instance.
func main() {
for _, arch := range []string{"amd64"} {
for _, opsys := range []string{"darwin", "linux"} {
gexe.SetVar("arch", arch).SetVar("os", opsys)
gexe.SetVar("binpath", fmt.Sprintf("build/%s/%s/mybinary", arch, opsys))
result := gexe.Envs("CGO_ENABLED=0 GOOS=$os GOARCH=$arch").Run("go build -o $binpath .")
if result != "" {
fmt.Printf("Build for %s/%s failed: %s\n", arch, opsys, result)
os.Exit(1)
}
fmt.Printf("Build %s/%s: %s OK\n", arch, opsys, echo.Eval("$binpath"))
}
}
}
Find more information in the README.