Skip to content

Prompt Types

Luke edited this page Jul 24, 2016 · 8 revisions

Out of the box, Tardy ships with a collection of prompt types that cover most of the common use cases.

SimplePrompt

The SimplePrompt allows you to specify a message and retrieve a string value in return. There are no restrictions on what the return value can be and no validation is done.

func SimplePrompt(message string, required Optionality, defaultValue string) Prompt

You can modify the required parameter to be Required or NotRequired. If it is Required then Tardy will re-prompt the user for entry. If it is NotRequired the value you set as the defaultValue will be used.

Example(s)

p.Prompt(tardy.SimplePrompt("What is your name?", tardy.Required, ""))
p.Prompt(tardy.SimplePrompt("What is your dog's name?", tardy.NotRequired, "Spot"))

SimpleSecurePrompt

Same as SimplePrompt but anything that you type will be hidden.

YesNoPrompt

The YesNoPrompt allows you to specify a message and retrieve a boolean value in return. Entry is restricted to a variety of acceptable yes or no values. A hint parameter allows you to define a string to instruct the user how to answer (e.g. "Y/n").

func YesNoPrompt(message string, hint string, required Optionality, 
  defaultValue bool) Prompt

You can modify the required parameter to be Required or NotRequired. If it is Required then Tardy will re-prompt the user for entry. If it is NotRequired the value you set as the defaultValue will be used.

Example(s)

p.Prompt(tardy.YesNoPrompt("Are you a fish?", "[y/N]", tardy.NotRequired, false))
p.Prompt(tardy.YesNoPrompt("Do you like Vegemite?", "[just type 'yes']", 
  tardy.Required, true))

SingleValuePrompt

The SingleValuePrompt allows you to specify a message and retrieve a string value in return. Entry is restricted to a variety of acceptable values as defined in the values parameter. A hint parameter allows you to define a string to instruct the user how to answer (e.g. "[dog, cat, fish]").

func SingleValuePrompt(message string, hint string, values []string, 
  required Optionality, defaultValue string) Prompt

You can modify the required parameter to be Required or NotRequired. If it is Required then Tardy will re-prompt the user for entry. If it is NotRequired the value you set as the defaultValue will be used.

Example(s)

p.Prompt(tardy.SingleValuePrompt("What animal are you?", "[dog or cat]", 
  []string{"dog", "cat"}, tardy.NotRequired, "dog"))
Clone this wiki locally