cli

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2018 License: Apache-2.0 Imports: 0 Imported by: 0

README

cli application examples

Integrate with promptui

It's easy to integrate promptui into Hiboot cli application

// declare main package
package main

// import cli starter and fmt
import (
	"github.com/hidevopsio/hiboot/pkg/starter/cli"
	"github.com/manifoldco/promptui"
	"fmt"
)

// define the command
type PromptuiCommand struct {
	// embedding cli.BaseCommand in each command
	cli.BaseCommand
}

// Init constructor
func (c *PromptuiCommand) Init() {
	c.Use = "promptui"
	c.Short = "promptui command"
	c.Long = "run promptui command for getting started"

}

// Run run the command
func (c *PromptuiCommand) Run(args []string) error {
	// define selections
	prompt := promptui.Select{
		Label: "Select Day",
		Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"},
	}

    // call prompt.Run() to get users selection
	_, result, err := prompt.Run()

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

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

	return nil
}

// main function
func main() {
	// create new cli application and run it
	cli.NewApplication(new(PromptuiCommand)).Run()
}

Documentation

Overview

Package cli provides hiboot command line application examples

Directories

Path Synopsis
cmd
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL