swerve

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

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

Go to latest
Published: Jan 20, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

README

swerve

Small library for creating interactive CLI applications

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Name is the command's unique name, used to identify it. Spaces aren't
	// supported.
	Name string
	// Aliases are optional additional names that can be used to refer to the
	// command. Spaces aren't supported.
	Aliases []string

	// Run is the command's main method, executed when the command is called
	// with valid arguments.
	Run func(p Prompt, args []string)

	// ValidateArgs is an optional function to validate a command's arguments
	// before being run.
	ValidateArgs func(p Prompt, args []string) (ok bool)

	// Desc is the command's shortest description. Desc is displayed when using
	// the builtin 'help' command to display the command list.
	Desc string
	// Usage is the command's usage string. If provided, it will be displayed
	// when using 'help <cmd>'
	Usage string
	// Help is the command's long string. If provided, it will be displayed when
	// using 'help <cmd>'
	Help string
}

Command represents a command of the interactive debugger.

func (*Command) Title

func (c *Command) Title() string

Title returnes the command's title, a formatted string consisting of it's name and aliases (if any).

type Prompt

type Prompt interface {
	Printf(format string, a ...interface{})
	Println(a ...interface{})

	Readline() string
	ReadPassword() string

	Clear()
}

Prompt represents a prompt with which the user interacts.

The Prompt is responsible both for reading user input as well as outputing back to the user. Each Shell holds a reference to a single Prompt, used to read commands and arguments from the user. Additionally, the same Prompt is passed to each command for user interaction capabilities.

type Shell

type Shell struct {
	// contains filtered or unexported fields
}

Shell represents an interactive shell, holding a list of given commands.

func New

func New(prompt string) *Shell

New returns a Shell with a terminal Prompt, with basic command name completion.

func NewWithPrompt

func NewWithPrompt(p Prompt) *Shell

NewWithPrompt returns a Shell with a specified Prompt.

func (*Shell) Add

func (s *Shell) Add(cmds ...Command)

Add adds commands to the Shell's command list.

Add will panic if a command with a name or alias identical to an existing command is added.

func (*Shell) Run

func (s *Shell) Run()

Run runs the Shell indefinitely, reading a line from the prompt and running the appropriate command with it's arguments.

type TerminalPrompt

type TerminalPrompt struct {
	// contains filtered or unexported fields
}

TerminalPrompt is a simple terminal Prompt implementation.

func NewTerminalPrompt

func NewTerminalPrompt(prompt string, l *liner.State) *TerminalPrompt

func (*TerminalPrompt) Clear

func (t *TerminalPrompt) Clear()

func (*TerminalPrompt) Printf

func (t *TerminalPrompt) Printf(format string, a ...interface{})

func (*TerminalPrompt) Println

func (t *TerminalPrompt) Println(a ...interface{})

func (*TerminalPrompt) ReadPassword

func (t *TerminalPrompt) ReadPassword() string

func (*TerminalPrompt) Readline

func (t *TerminalPrompt) Readline() string

Jump to

Keyboard shortcuts

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