Documentation ¶
Overview ¶
Package ishell implements an interactive shell.
Index ¶
- func ExitErr(err string) error
- func NewErr(err string, level ErrLevel) error
- func PanicErr(err string) error
- func StopErr(err string) error
- func WarnErr(err string) error
- type CmdFunc
- type ErrLevel
- type Shell
- func (s *Shell) Active() bool
- func (s *Shell) ClearScreen() error
- func (s *Shell) Commands() []string
- func (s *Shell) IgnoreCase(ignore bool)
- func (s *Shell) Print(val ...interface{})
- func (s *Shell) PrintCommands()
- func (s *Shell) Println(val ...interface{})
- func (s *Shell) ReadLine() string
- func (s *Shell) ReadMultiLines(terminator string) string
- func (s *Shell) ReadMultiLinesFunc(f func(string) bool) string
- func (s *Shell) ReadPassword(mask bool) string
- func (s *Shell) Register(command string, function CmdFunc)
- func (s *Shell) RegisterGeneric(function CmdFunc)
- func (s *Shell) SetOut(writer io.Writer)
- func (s *Shell) SetPrompt(prompt string)
- func (s *Shell) ShowPrompt(show bool)
- func (s *Shell) Start()
- func (s *Shell) Stop()
- func (s *Shell) Unregister(command string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CmdFunc ¶
CmdFunc represents a command function that is called after an input to the shell. The shell input is split into command and arguments like cli args and the arguments are passed to this function. The shell will print output if output != "".
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
func NewShell ¶
func NewShell() *Shell
NewShell creates a new shell with default settings. Uses standard output and default prompt ">>".
func (*Shell) ClearScreen ¶
ClearScreen clears the screen. Same behaviour as running 'clear' in unix terminal or 'cls' in windows cmd.
func (*Shell) IgnoreCase ¶
IgnoreCase specifies whether commands should not be case sensitive. Defaults to false i.e. commands are case sensitive. If true, commands must be registered in lower cases. e.g. shell.Register("cmd", ...)
func (*Shell) PrintCommands ¶
func (s *Shell) PrintCommands()
PrintCommands prints a space separated list of registered commands to the shell.
func (*Shell) Println ¶
func (s *Shell) Println(val ...interface{})
Println prints to output and ends with newline character.
func (*Shell) ReadMultiLines ¶
ReadMultiLines reads multiple lines from standard input. It stops reading when terminator is encountered at the end of the line. It returns the lines read including terminator. For more control, use ReadMultiLinesFunc.
func (*Shell) ReadMultiLinesFunc ¶
ReadMultiLinesFunc reads multiple lines from standard input. It passes each read line to f and stops reading when f returns false.
func (*Shell) ReadPassword ¶
ReadPassword reads password from standard input without echoing the characters. If mask is true, each character will be represented with asterisks '*'. Note that this only works as expected when the standard input is a terminal.
func (*Shell) Register ¶
Register registers a function for command. It overwrites existing function, if any.
func (*Shell) RegisterGeneric ¶
RegisterGeneric registers a generic function for all inputs. It is called if the shell input could not be handled by any of the registered functions. Unlike Register, the entire line is passed as first argument to CmdFunc.
func (*Shell) SetPrompt ¶
SetPrompt sets the prompt string. The string to be displayed before the cursor.
func (*Shell) ShowPrompt ¶
ShowPrompt sets whether prompt should show when requesting input for ReadLine and ReadPassword. Defaults to true.
func (*Shell) Start ¶
func (s *Shell) Start()
Start starts the shell. It reads inputs from standard input and calls registered functions accordingly. This function blocks until the shell is stopped.
func (*Shell) Stop ¶
func (s *Shell) Stop()
Stop stops the shell. This will stop the shell from auto reading inputs and calling registered functions. A stopped shell is only inactive but totally functional. Its functions can still be called.
func (*Shell) Unregister ¶
Unregister unregisters a function for a command