Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status Coverage Status Go Report Card GoDoc

Simple, easy to use input handler for the CLI


go get
# or with dep
dep ensure -add


package main

import (


func main() {
	// Input (can be empty)
	someInput := input.Prompt("How was your day").(string)

	// Required Input
	someInput = input.Prompt("What is your favourite tv-show", input.RequiredValidator).(string)

	// Boolean Input (y/n)
	boolInput := input.Prompt("Are you sure (y/n)", input.RequiredValidator, input.BooleanValidator).(bool)

	// Boolean Input with default (Y/n)
	var inputResult bool
	switch boolInput2 := input.Prompt("Are you sure (Y/n)", input.BooleanValidator).(type) {
	case bool:
		// user set it with yes or no
		inputResult = boolInput2
		// user just pressed enter - set default
		inputResult = true

	// File Input
	file := input.Prompt("Location of the config file?", input.RequiredValidator, input.FileValidator).(string)
	fmt.Println("File location:", file)


List of built-in validators:

  • RequiredValidator: ensures the input is not empty
  • PathValidator: ensures the input is valid looking path
  • DirectoryValidator: ensures the input is a valid and existing directory
  • FileValidator: ensures the input is a valid and existing file
  • IntegerValidator: ensures and converts the input to a integer with strconv.Atoi
  • BooleanValidator: ensures and converts the input to a boolean
    • true: 1, t, true, y, yes
    • false: 0, f, false, n, no

Create your own - you just need to create a input.ValidatorFunction:

func ContainsSomethingValidator(input string) (interface{}, error) {
    if !strings.Contains("something") {
        return nil, fmt.Errorf("Input %s does not contain 'something'", input)

    return input, nil


Everyone is encouraged to help improve this project. Here are a few ways you can help: