cli

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	// Description returns a ~40 character sentence describing the command.
	Description() string

	// Prefixes defines the names that the command will be invoked under.
	//
	// This is a slice to allow for alternatives and shorthands to be considered
	// as a prefix for the command.
	Prefixes() []string

	// Handle executes the given subcmd, if any, with the given arguments.
	Handle(subcmd string, args ...string)

	// PrintHelp prints a helpful overview describing the Command its subcommands.
	PrintHelp()
}

A Command is a single command that a Server supports.

Commands display description and help information. Each Command may support any number of sub-commands, all of which receive further arguments in a byte slice.

Commands are registered with a Server before beginning the Server's loop.

type Prompter

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

func NewPrompter

func NewPrompter(cli *Server, cl client.Client, logger log.Logger) *Prompter

func (*Prompter) PromptDecimal

func (p *Prompter) PromptDecimal(prompt string, defVal *decimal.Decimal, filters ...func(decimal.Decimal) (decimal.Decimal, bool)) (decimal.Decimal, bool)

PromptDecimal prompts the user for a valid decimal input.

If defVal is not nil, the prompt will be pre-populated with the default value.

Additionally, any number of filter funcs can be passed in to perform custom validation and filtering on the user's input. Filter functions receive the value received from the prompt and return the new value and and indicator whether the value is valid.

func (*Prompter) PromptInt

func (p *Prompter) PromptInt(prompt string, defVal *int, filters ...func(int) (int, bool)) (int, bool)

PromptInt prompts the user for a valid integer input.

If defVal is not nil, the prompt will be pre-populated with the default value.

Additionally, any number of filter funcs can be passed in to perform custom validation and filtering on the user's input. Filter functions receive the value received from the prompt and return the new value and and indicator whether the value is valid.

func (*Prompter) PromptItemTypeDetail

func (p *Prompter) PromptItemTypeDetail(prompt string, initialInput string) (*evedb.ItemTypeDetail, bool)

PromptItemTypeDetail prompts the user for a valid item type input.

If the user enters an integer, it is treated as the item's Type ID. Otherwise, the value is used to lookup item types.

This function also accepts an initial input that should be used to as the first round of prompt input.

func (*Prompter) PromptRegion

func (p *Prompter) PromptRegion(prompt string, initialInput string) (*evedb.Region, bool)

PromptRegion prompts the user for a valid region input.

If the user enters an integer, it is treated as the region's Region ID. Otherwise, the value is used to lookup regions.

This function also accepts an initial input that should be used to as the first round of prompt input.

func (*Prompter) PromptString

func (p *Prompter) PromptString(prompt string, defVal *string, filters ...func(string) (string, bool)) (string, bool)

PromptString prompts the user for any string input.

If defVal is not nil, the prompt will be pre-populated with the default value.

Additionally, any number of filter funcs can be passed in to perform custom validation and filtering on the user's input. Filter functions receive the value received from the prompt and return the new value and and indicator whether the value is valid.

func (*Prompter) PromptStringWithArgs

func (p *Prompter) PromptStringWithArgs(prompt string, defVal *string, filters ...func(string) (string, bool)) (string, []string, bool)

PromptStringWithArgs prompts the user for any string input.

This function differs from PromptString in that it will split the received input by spaces, returning the first value as the main value, and a slice of additional arguments.

If defVal is not nil, the prompt will be pre-populated with the default value.

Additionally, any number of filter funcs can be passed in to perform custom validation and filtering on the user's input. Filter functions receive the value received from the prompt and return the new value and and indicator whether the value is valid.

type Server

type Server struct {
	*liner.State
	// contains filtered or unexported fields
}

A Server handles command-line requests and prints responses to standard output.

func NewServer

func NewServer(logger log.Logger) *Server

NewServer initializes a new CLI server.

func (*Server) LoopCLI

func (srv *Server) LoopCLI()

LoopCLI starts an endless loop to perform commands read from stdin.

func (*Server) PrintHelp

func (srv *Server) PrintHelp()

PrintHelp prints the application-level help text.

func (*Server) SetCommands

func (srv *Server) SetCommands(commands ...Command)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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