Skip to content

Releases: vladimirvivien/gexe

v0.3.0

09 Jun 20:04
14fa016
Compare
Choose a tag to compare

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

Full Changelog: v0.2.0...v0.3.0

Release v0.2.0

06 Nov 20:50
35a3a02
Compare
Choose a tag to compare

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

02 Oct 04:24
4d4f3dd
Compare
Choose a tag to compare

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

02 May 18:55
6149013
Compare
Choose a tag to compare

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.