Skip to content

deiwin/interact

Repository files navigation

Interact

A Golang utility belt for interacting with the user over a CLI

Build Status Coverage GoDoc

Example interaction

Code like this:

actor := interact.NewActor(os.Stdin, os.Stdout)

message := "Please enter something that's not empty"
notEmpty, err := actor.Prompt(message, checkNotEmpty)
if err != nil {
  log.Fatal(err)
}
message = "Please enter a positive number"
n1, err := actor.PromptAndRetry(message, checkNotEmpty, checkIsAPositiveNumber)
if err != nil {
  log.Fatal(err)
}
message = "Please enter another positive number"
n2, err := actor.PromptOptionalAndRetry(message, "7", checkNotEmpty, checkIsAPositiveNumber)
if err != nil {
  log.Fatal(err)
}
fmt.Printf("Thanks! (%s, %s, %s)\n", notEmpty, n1, n2)

Can create an interaction like this:

asciicast

For a more comprehensive example see the example test.

About

A Golang utility belt for interacting with the user over a CLI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages