Skip to content

Go library facilitating the creation of programs that resemble bash scripts.

License

Notifications You must be signed in to change notification settings

jojomi/go-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-script

Go library facilitating the creation of programs that resemble bash scripts.

Rationale

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.

Methods

GoDoc CircleCI Coverage Status Go Report Card

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.

Usage

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

Warning

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.

On The Shoulders or Giants

Libraries Used in go-script

  • 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

Other Libraries

Some libraries have proven highly useful in conjunction with go-script:

More inspiration can be found at awesome-go.

Development

Comments, issues, and of course pull requests are highly welcome.

If you create a Merge Request, be sure to execute ./precommit.sh beforehand.

License

see LICENSE

About

Go library facilitating the creation of programs that resemble bash scripts.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published