- Notifications
You must be signed in to change notification settings - Fork0
Go library facilitating the creation of programs that resemble bash scripts.
License
jojomi/go-script
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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 unparalleledbash
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 forexecuting external commands (includingenvironment variables), maintaining aworking directory, handlingfiles and directories (cp/mv), and evaluatingcommand output (exit code, stdout/stderr). You can use methods forrequesting input from users, printprogress bars and activity indicators, and use helpers forprinting colorful or bold text.
package mainimport ("fmt""github.com/jojomi/go-script")funcmain() {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 theexamples
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, forkaway 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 withgo-script
:
More inspiration can be found atawesome-go.
Comments, issues, and of course pull requests are highly welcome.
If you create a Merge Request, be sure to execute./precommit.sh
beforehand.
seeLICENSE
About
Go library facilitating the creation of programs that resemble bash scripts.