Documentation
¶
Overview ¶
This package is used to implement a "line oriented command interpreter", inspired by the python package with
the same name http://docs.python.org/2/library/cmd.html
Usage:
commander := &Cmd{...}
commander.Init()
cmd := NewCommand(name,Option...)
commander.Add(cmd)
commander.CmdLoop()
Index ¶
- func ColorizeString(text string)
- func PrintDefaults(f *flag.FlagSet)
- func RightJustifyText(text string) string
- type Cmd
- func (cmd *Cmd) Add(command *Command)
- func (cmd *Cmd) AddCommandCompleter()
- func (cmd *Cmd) CmdLoop()
- func (cmd *Cmd) Echo(line string) (stop bool)
- func (cmd *Cmd) GetRestartLoop() bool
- func (cmd *Cmd) Go(line string) (stop bool)
- func (cmd *Cmd) Help(command *Command, line string) (stop bool)
- func (cmd *Cmd) Init()
- func (cmd *Cmd) OneCmd(line string) (stop bool)
- func (cmd *Cmd) RestartLoop()
- func (cmd *Cmd) SetRestartLoop(restart bool)
- type Command
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorizeString ¶
func ColorizeString(text string)
func PrintDefaults ¶
Prints the default values of all defined flags in the set.
func RightJustifyText ¶
Types ¶
type Cmd ¶
type Cmd struct {
// the prompt string
Prompt string
// the history file
HistoryFile string
// this function is called before starting the command loop
PreLoop func()
// this function is called before terminating the command loop
PostLoop func()
// this function is called before executing the selected command
PreCmd func(string)
// this function is called after a command has been executed
// return true to terminate the interpreter, false to continue
PostCmd func(string, bool) bool
// this function is called if the last typed command was an empty line
EmptyLine func()
// this function is called if the command line doesn't match any existing command
// by default it displays an error message
Default func(string)
// this function is called to implement command completion.
// it should return a list of words that match the input text
Complete func(string, string, int, int) []string
// if true, enable shell commands
EnableShell bool
// this is the list of available commands indexed by command name
Commands map[string]*Command
// contains filtered or unexported fields
}
This the the "context" for the command interpreter
func (*Cmd) Add ¶
Add a command to the command interpreter. Overrides a command with the same name, if there was one
func (*Cmd) AddCommandCompleter ¶
func (cmd *Cmd) AddCommandCompleter()
Add a completer that matches on command names
func (*Cmd) CmdLoop ¶
func (cmd *Cmd) CmdLoop()
This is the command interpreter entry point. It displays a prompt, waits for a command and executes it until the selected command returns true
func (*Cmd) GetRestartLoop ¶
func (*Cmd) Help ¶
Default help command. It lists all available commands or it displays the help for the specified command
func (*Cmd) RestartLoop ¶
func (cmd *Cmd) RestartLoop()
func (*Cmd) SetRestartLoop ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
This is used to describe a new command
func NewCommand ¶
func (*Command) AddSubCommand ¶
func (*Command) GetBoolFlag ¶
func (*Command) GetCmdline ¶
Click to show internal directories.
Click to hide internal directories.