Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Interactive prompt for command-line applications

License

NotificationsYou must be signed in to change notification settings

manifoldco/promptui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Interactive prompt for command-line applications.

We built Promptui because we wanted to make it easy and fun to explore cloudservices withmanifold cli.

Code of Conduct |Contribution Guidelines

GitHub releaseGoDocTravisGo Report CardLicense

Overview

promptui

Promptui is a library providing a simple interface to create command-lineprompts for go. It can be easily integrated intospf13/cobra,urfave/cli or any cli go application.

Promptui has two main input modes:

  • Prompt provides a single line for user input. Prompt supportsoptional live validation, confirmation and masking the input.

  • Select provides a list of options to choose from. Select supportspagination, search, detailed view and custom templates.

For a full list of options checkGoDoc.

Basic Usage

Prompt

package mainimport ("errors""fmt""strconv""github.com/manifoldco/promptui")funcmain() {validate:=func(inputstring)error {_,err:=strconv.ParseFloat(input,64)iferr!=nil {returnerrors.New("Invalid number")}returnnil}prompt:= promptui.Prompt{Label:"Number",Validate:validate,}result,err:=prompt.Run()iferr!=nil {fmt.Printf("Prompt failed %v\n",err)return}fmt.Printf("You choose %q\n",result)}

Select

package mainimport ("fmt""github.com/manifoldco/promptui")funcmain() {prompt:= promptui.Select{Label:"Select Day",Items: []string{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},}_,result,err:=prompt.Run()iferr!=nil {fmt.Printf("Prompt failed %v\n",err)return}fmt.Printf("You choose %q\n",result)}

More Examples

See full list ofexamples


[8]ページ先頭

©2009-2025 Movatter.jp