GithubHelp home page GithubHelp logo

azrod / promptui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from manifoldco/promptui

0.0 0.0 0.0 181 KB

Interactive prompt for command-line applications

Home Page: https://www.manifold.co

License: BSD 3-Clause "New" or "Revised" License

Go 98.64% Makefile 1.36%

promptui's Introduction

promptui

Interactive prompt for command-line applications.

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

Code of Conduct | Contribution Guidelines

GitHub release GoDoc Travis Go Report Card License

Overview

promptui

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

Promptui has two main input modes:

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

  • Select provides a list of options to choose from. Select supports pagination, 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/azrod/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/azrod/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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.