ask

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 6 Imported by: 22

README

ask

A Golang library for prompting a user for passwords and such.

Reading from stdin and writing to stdout interferes with a user's ability to pipe data into or out of a program. This is most evident when doing things such as prompting a user for a password.

For example, given a program which requests a password from a user and then proceeds to read the remainder of stdin as input. If the user then pipes a file into the program, the first line is read as the password rather than the user being given an opportunity to enter the correct password.

Instead, this library interacts with the user directly, allowing the user to be prompted and respond without interfering with stdin or stdout.

Use judiciously. While it may be tempting to use this as the only input method for a program, this precludes a user from automating input.

Usage

ask.Ask gets input from the user normally, while ask.HiddenAsk prevents echoing of the user's input. ask.Print is also available to compliment the ask.Ask* variants.

import (
  "github.com/miquella/ask"
)

func getPassword() (string, error) {
    err := ask.Print("Warning! I am about to ask you for a password!\n")
    if err != nil {
        return "", err
    }

    return ask.HiddenAsk("Password: ")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ask

func Ask(prompt string) (string, error)

func Close

func Close() error

func CloseInput

func CloseInput() error

func CloseOutput

func CloseOutput() error

func HiddenAsk

func HiddenAsk(prompt string) (string, error)

func IsInteractive

func IsInteractive() bool

func Print

func Print(str string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL