cobraprompt

package module
v0.0.0-...-68ff80e Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 6 Imported by: 0

README

Cobra-Prompt

Connect cobra and go-prompt

https://github.com/c-bata/go-prompt

https://github.com/spf13/cobra

Example

This example uses glide.

cd example
glide install
go build -o cobra-prompt
./cobra-prompt

ps: 我之前使用此库,用于godbg项目的交互式命令开发,后来发现背后使用的go-prompt限制比较多,使用liner代替cobra-prompt。

Documentation

Index

Constants

View Source
const CALLBACK_ANNOTATION = "cobra-prompt"

CALLBACK_ANNOTATION

Variables

This section is empty.

Functions

This section is empty.

Types

type CobraPrompt

type CobraPrompt struct {
	// RootCmd is the start point, all its sub commands and flags will be available as suggestions
	RootCmd *cobra.Command

	// GoPromptOptions is for customize go-prompt
	// see https://github.com/c-bata/go-prompt/blob/master/option.go
	GoPromptOptions []prompt.Option

	// DynamicSuggestionsFunc will be executed if an command has CALLBACK_ANNOTATION as an annotation. If it's included
	// the value will be provided to the DynamicSuggestionsFunc function.
	DynamicSuggestionsFunc func(annotation string, document prompt.Document) []prompt.Suggest

	// ResetFlagsFlag will add a new persistent flag to RootCmd. This flags can be used to turn off flags value reset
	ResetFlagsFlag bool

	// SilentPrompt suppress the prompt when there's no input
	EnableSilentPrompt bool

	// SilentPromptWithShowAtStart suppress the prompt when there's no input, but show at start
	EnableShowAtStart bool
}

CobraPrompt requires RootCmd to run

func (CobraPrompt) Run

func (co CobraPrompt) Run()

Run will automatically generate suggestions for all cobra commands and flags defined by RootCmd and execute the selected commands. Run will also reset all given flags by default, see ResetFlagsFlag

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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