Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

jojomi/go-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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.

Methods

GoDocCircleCICoverage StatusGo Report Card

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.

Usage

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

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, forkaway to keep a certain API status or use vendoring (dep) to keep your desired state.

On The Shoulders or Giants

Libraries Used ingo-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 withgo-script:

More inspiration can be found atawesome-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

seeLICENSE

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp