Documentation
¶
Index ¶
Constants ¶
View Source
const DynamicSuggestionsAnnotation = "cobra-prompt-dynamic-suggestions"
DynamicSuggestionsAnnotation for dynamic suggestions.
View Source
const PersistFlagValuesFlag = "persist-flag-values"
PersistFlagValuesFlag the flag that will be avaiailable when PersistFlagValues is true
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/tengteng/go-prompt/blob/master/option.go GoPromptOptions []prompt.Option // DynamicSuggestionsFunc will be executed if an command has CallbackAnnotation as an annotation. If it's included // the value will be provided to the DynamicSuggestionsFunc function. DynamicSuggestionsFunc func(annotationValue string, document *prompt.Document) []prompt.Suggest // PersistFlagValues will persist flags. For example have verbose turned on every command. PersistFlagValues bool // ShowHelpCommandAndFlags will make help command and flag for every command available. ShowHelpCommandAndFlags bool // DisableCompletionCommand will disable the default completion command for cobra DisableCompletionCommand bool // ShowHiddenCommands makes hidden commands available ShowHiddenCommands bool // ShowHiddenFlags makes hidden flags available ShowHiddenFlags bool // AddDefaultExitCommand adds a command for exiting prompt loop AddDefaultExitCommand bool // OnErrorFunc handle error for command.Execute, if not set print error and exit OnErrorFunc func(err error) // InArgsParser adds a custom parser for the command line arguments (default: strings.Fields) InArgsParser func(args string) []string // SuggestionFilter will be uses when filtering suggestions as typing SuggestionFilter func(suggestions []prompt.Suggest, document *prompt.Document) []prompt.Suggest }
CobraPrompt given a Cobra command it will make every flag and sub commands available as suggestions. Command.Short will be used as description for the suggestion.
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 PersistFlagValues
func (CobraPrompt) RunContext ¶
func (co CobraPrompt) RunContext(ctx context.Context)
RunContext same as Run but with context
Click to show internal directories.
Click to hide internal directories.