https://github.com/deiwin/interact
A Golang utility belt for interacting with the user over a CLI
https://github.com/deiwin/interact
cli
Last synced: 5 months ago
JSON representation
A Golang utility belt for interacting with the user over a CLI
- Host: GitHub
- URL: https://github.com/deiwin/interact
- Owner: deiwin
- License: mit
- Created: 2015-04-05T12:30:08.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-09T13:08:53.000Z (about 11 years ago)
- Last Synced: 2025-03-26T09:41:10.061Z (about 1 year ago)
- Topics: cli
- Language: Go
- Homepage: https://godoc.org/github.com/deiwin/interact
- Size: 104 KB
- Stars: 129
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Interact
A Golang utility belt for interacting with the user over a CLI
[](https://travis-ci.org/deiwin/interact)
[](http://gocover.io/github.com/deiwin/interact)
[](https://godoc.org/github.com/deiwin/interact)
## Example interaction
Code like this:
```go
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:

For a more comprehensive example see the [example test](https://github.com/deiwin/interact/blob/master/example_test.go).