commander

package module
v0.0.0-...-b9c57d3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Commander

A golang cli framework. Please see examples for usage.

Docs

This is an early alpha! API is subject to changes!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SimpleSuggestions

func SimpleSuggestions(text ...string) []prompt.Suggest

SimpleSuggestions converts strings into prompt.Suggest structs

Types

type Command

type Command struct {
	// name of the command (REQUIRED)
	Cmd string
	// description of the command (OPTIONAL)
	Description string
	// callback which gets executed (OPTIONAL)
	RunCallback func(Commander, Command, []string) error
	// callback to provide command argument suggestions (OPTIONAL)
	ArgumentComplete func(...string) []prompt.Suggest
	// commander to support nesting interfaces (OPTIONAL)
	SubCommander Commander
	// list of allowed first arguments (OPTIONAL)
	Options []string

	// validator function to validate arguments (OPTIONAL)
	Validate func(args []string) bool
	// contains filtered or unexported fields
}

Command represents an interactive command

type Commander

type Commander interface {
	// Processes commands in a loop until ctrl+d/ctrl+c is pressed. Optionally takes a list of values for the prefix string
	Run(prefixArgs ...string) error
	// add a new command to the current commander
	AddCommand(c Command) error
	// current prefix args (not threadsafe!)
	PrefixArgs() []string
	// set a custom writer for status messages (uses os.Stdout by default)
	SetWriter(io.Writer)
}

Commander implements the cli parsing and handling

func New

func New(prefixTemplate string, options ...prompt.Option) Commander

New creates a new commander with the given prefix format template and prompt options

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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