promptui

Interactive prompt for command-line applications
授权协议 BSD-3-Clause License
开发语言 Google Go
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 池麒
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

promptui

Interactive prompt for command-line applications.

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

Code of Conduct |Contribution Guidelines

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 check GoDoc.

Basic Usage

Prompt

package main

import (
	"errors"
	"fmt"
	"strconv"

	"github.com/manifoldco/promptui"
)

func main() {
	validate := func(input string) error {
		_, err := strconv.ParseFloat(input, 64)
		if err != nil {
			return errors.New("Invalid number")
		}
		return nil
	}

	prompt := promptui.Prompt{
		Label:    "Number",
		Validate: validate,
	}

	result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

Select

package main

import (
	"fmt"

	"github.com/manifoldco/promptui"
)

func main() {
	prompt := promptui.Select{
		Label: "Select Day",
		Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
			"Saturday", "Sunday"},
	}

	_, result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

More Examples

See full list of examples

相关阅读

相关文章

相关问答

相关文档