Go library facilitating the creation of programs that resemble bash scripts.
Go's advantages like static binding and a huge modern standard library do suggest its usage for little tools that used to be implemented as shell scripts.
This library is intended as a wrapper for typical tasks shell scripts include and aimed at bringing the LOC size closer to unparalleled bash
shortness.
go-script
uses several other libraries that enable you to create scripts with a good user feedback and user interface on the command line.
This library strives for a good test coverage even though it is not always easy for user facing code like this.
The methods include helpers for executing external commands (including environment variables), maintaining a working directory, handling files and directories (cp/mv), and evaluating command output (exit code, stdout/stderr). You can use methods for requesting input from users, print progress bars and activity indicators, and use helpers for printing colorful or bold text.
package main
import (
"fmt"
"github.com/jojomi/go-script"
)
func main() {
sc := script.NewContext()
sc.MustCommandExist("date")
sc.SetWorkingDir("/tmp")
pr := sc.MustExecuteSilent("date", "-R")
fmt.Print("The current date: ", pr.Output())
fmt.Println(pr.StateString())
}
More example can be found in the examples
directory, execute them like this:
go run examples/command-checking/command-checking.go
This library's API is not yet stable. Use at your own discretion.
You should be prepared for future API changes of any kind.
In doubt, fork away to keep a certain API status or use vendoring (dep) to keep your desired state.
-
go-isatty to detect terminal capabilities
-
survey for user interactions
-
wow for activity indicators
-
pb for progress bars
-
color for printing colorful and bold output
-
go-shutil (forked) for copying data
-
afero for abstracting filesystem for easier testing
Some libraries have proven highly useful in conjunction with go-script
:
More inspiration can be found at awesome-go.
Comments, issues, and of course pull requests are highly welcome.
If you create a Merge Request, be sure to execute ./precommit.sh
beforehand.
see LICENSE