Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 13 days 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 (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-09T13:08:53.000Z (over 9 years ago)
- Last Synced: 2024-08-01T16:18:08.738Z (3 months ago)
- Topics: cli
- Language: Go
- Homepage: https://godoc.org/github.com/deiwin/interact
- Size: 104 KB
- Stars: 129
- Watchers: 5
- 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[![Build Status](https://travis-ci.org/deiwin/interact.svg?branch=master)](https://travis-ci.org/deiwin/interact)
[![Coverage](http://gocover.io/_badge/github.com/deiwin/interact?0)](http://gocover.io/github.com/deiwin/interact)
[![GoDoc](https://godoc.org/github.com/deiwin/interact?status.svg)](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:
![asciicast](https://cloud.githubusercontent.com/assets/2261897/7066876/6194ec42-decf-11e4-823a-019f921f52a1.gif)
For a more comprehensive example see the [example test](https://github.com/deiwin/interact/blob/master/example_test.go).