Documentation ¶
Overview ¶
Package prompter is a helper for go-prompt (https://github.com/c-bata/go-prompt).
Index ¶
- func ImportConfig(input []byte) error
- type Argument
- type CmdArgs
- type Command
- type Completer
- func (c *Completer) Complete(in prompt.Document) []prompt.Suggest
- func (c *Completer) CompleteArgs(args []string) []prompt.Suggest
- func (c *Completer) Execute(in string)
- func (c *Completer) ExecuteArgs(args []string) bool
- func (c *Completer) RegisterCommands(commands ...Command) error
- func (c *Completer) RegisterOptions(opts ...Argument) error
- type CompleterFunc
- type Config
- type ExecutorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ImportConfig ¶
ImportConfig converts a serialized JSON into the config.
Types ¶
type Argument ¶
type Argument struct { Name string Description string ArgumentCompleter CompleterFunc Repeatable bool }
Argument represents arguments for a subcommand.
type CmdArgs ¶
CmdArgs contains the arguments passed to the command.
func (CmdArgs) GetFirstValue ¶
GetFirstValue returns the first value of an argument.
type Command ¶
type Command struct { Name string // Name of command (to be typed on cli) Description string // Description shown for command by the completer Completer *Completer Executor ExecutorFunc // Function that executes when command is run Hide func() bool // function to optionally hide a command from the completer SubCommands []Command // List of completable subcommands Arguments []Argument // List of completable arguments }
func ExitCommand ¶
ExitCommand returns a command that exits the application.
func (*Command) AddArguments ¶
AddOption creates an option and adds it to the command.
func (*Command) AddSubCommands ¶
AddSubCommands adds one or more subcommands to the higher-level command.
type Completer ¶
type Completer struct { Commands map[string]*Command Options map[string]*Argument // contains filtered or unexported fields }
Completer represents one go-prompt completer.
func NewCompleter ¶
func NewCompleter() *Completer
NewCompleter creates and returns a new *Completer.
func (*Completer) CompleteArgs ¶
func (*Completer) ExecuteArgs ¶
func (*Completer) RegisterCommands ¶
RegisterCommands adds one or more top-level commands to the completer.
func (*Completer) RegisterOptions ¶
RegisterOptions adds one or more options to the completer.
type CompleterFunc ¶
CompleterFunc returns completion options for commands.
type Config ¶
Config is used as a key/value store to persist state between commands.
func GetConfig ¶
func GetConfig() Config
GetConfig returns the config. Creates it when it's called for the first time.