Socket
Book a DemoInstallSign in
Socket

github.com/tcnksm/go-input

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/tcnksm/go-input

Source
Go
Version
v0.0.0-20180404061846-548a7d7a8ee8
Version published
Created
Source

go-input Go Documentation Travis MIT License

go-input is a Go package for reading user input in console.

Here is the some good points compared with other/similar packages. It can handle SIGINT (Ctrl+C) while reading input and returns error. It allows to change IO interface as io.Writer and io.Reader so it's easy to test of your go program with this package (This package is also well-tested!). It also supports raw mode input (reading input without prompting) for multiple platform (Darwin, Linux and Windows). Not only this it allows to prompt complex input via Option struct.

The documentation is on GoDoc.

Install

Use go get to install this package:

$ go get github.com/tcnksm/go-input

Usage

The following is the simple example,

ui := &input.UI{
    Writer: os.Stdout,
    Reader: os.Stdin,
}

query := "What is your name?"
name, err := ui.Ask(query, &input.Options{
    Default: "tcnksm",
    Required: true,
    Loop:     true,
})

You can check other examples in here.

Contribution

  • Fork (https://github.com/tcnksm/go-input/fork)
  • Create a feature branch
  • Commit your changes
  • Rebase your local changes against the master branch
  • Run test suite with the go test ./... command and confirm that it passes
  • Run gofmt -s
  • Create new Pull Request

Author

Taichi Nakashima

FAQs

Package last updated on 04 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts