cobraprompt

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: MIT Imports: 14 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

Documentation

Index

Constants

View Source
const CALLBACK_ANNOTATION = "cobra-prompt"

CALLBACK_ANNOTATION

Variables

This section is empty.

Functions

func ConsulInit added in v0.2.0

func ConsulInit(token string, env string, profile string) *api.Client

func FileExists added in v0.2.0

func FileExists(filename string) bool

checks if a file exists

func FindProfile added in v0.2.0

func FindProfile() ([]string, []prompt.Suggest)

find the profiles on the existing machine

func GetEnv added in v0.2.0

func GetEnv(profile string) (string, string)

func GetPlatformId added in v0.2.0

func GetPlatformId(c *api.Client) []prompt.Suggest

func GetPlatformNames added in v0.2.0

func GetPlatformNames(c *api.Client) []prompt.Suggest

func GetSecret added in v0.2.0

func GetSecret(dc string, profile string) (string, error)

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

	Consul *api.Client
}

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