Documentation
¶
Overview ¶
Package prompter is utility for easy prompting
Index ¶
- Constants
- func Choose(message string, choices []string, defaultChoice string) string
- func Password(message string) string
- func Prompt(message, defaultAnswer string) string
- func Regexp(message string, reg *regexp.Regexp, defaultAnswer string) string
- func YN(message string, defaultToYes bool) bool
- func YesNo(message string, defaultToYes bool) bool
- type Prompter
Examples ¶
Constants ¶
View Source
const VERSION = "0.5.1"
VERSION version of prompter
Variables ¶
This section is empty.
Functions ¶
func Choose ¶
Choose make a choice
Example ¶
package main import ( "fmt" "github.com/Songmu/prompter" ) func main() { lang := prompter.Choose("Which language do you like the most?", []string{"Perl", "Golang", "Scala", "Ruby"}, "Perl") fmt.Println("Perl") fmt.Printf("Great! You like %s!", lang) }
Output: Which language do you like the most? (Perl/Golang/Scala/Ruby) [Perl]: Perl Great! You like Perl!
func Password ¶
Password asks password
Example ¶
package main import ( "fmt" "github.com/Songmu/prompter" ) func main() { passwd := prompter.Password("Enter your password") _ = passwd fmt.Println("****") fmt.Print("I got your password! :P") }
Output: Enter your password: **** I got your password! :P
func Prompt ¶
Prompt simple prompting
Example ¶
package main import ( "fmt" "github.com/Songmu/prompter" ) func main() { answer := prompter.Prompt("Enter your twitter ID", "") _ = answer fmt.Println("Songmu") fmt.Printf("Hi Songmu!") }
Output: Enter your twitter ID: Songmu Hi Songmu!
func YN ¶
YN y/n choice
Example ¶
package main import ( "fmt" "github.com/Songmu/prompter" ) func main() { if prompter.YN("Do you like sushi?", true) { fmt.Println("y") fmt.Print("Nice! Let's go sushi bar!") } }
Output: Do you like sushi? (y/n) [y]: y Nice! Let's go sushi bar!
Types ¶
type Prompter ¶
type Prompter struct { Message string // choices of answer Choices []string IgnoreCase bool Default string // specify answer pattern by regexp. When both Choices and Regexp are specified, Regexp takes a priority. Regexp *regexp.Regexp // for passwords and so on. NoEcho bool UseDefault bool // contains filtered or unexported fields }
Prompter is object for prompting
Example ¶
package main import ( "fmt" "github.com/Songmu/prompter" ) func main() { input := (&prompter.Prompter{ Choices: []string{"aa", "bb", "cc"}, Default: "aa", Message: "please select", IgnoreCase: true, }).Prompt() fmt.Println("aa") fmt.Printf("your input is %s.", input) }
Output: please select (aa/bb/cc) [aa]: aa your input is aa.
Click to show internal directories.
Click to hide internal directories.