Documentation ¶
Overview ¶
Package command provides CLI style interactive commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSkipHears suggests that a handler has dealt with a command, // and than any subsequent Hears handlers should be skipped. ErrSkipHears = errors.New("skip hear messages") // ErrUnknownCommand is returned by a command mux if the command did // not match any of it's registered handlers. ErrUnknownCommand = errors.New("unknown command") // ErrBadCLI implies that we could not process this message as a // command line. E.g. due to potentially mismatched quoting or bad // escaping. ErrBadCLI = errors.New("could not process as command line") )
Functions ¶
Types ¶
type Command ¶
type Command struct { Use string Short string Long string Example string PersistentPreRun RunFunc PreRun RunFunc Run RunFunc PostRun RunFunc PersistentPostRun RunFunc SilenceErrors bool SilenceUsage bool // contains filtered or unexported fields }
Command describe a CLI type command that can be executed by a user. It a wrapper around an github.com/spf13/cobra command
func FromContext ¶
FromContext retrieves the Command the caused the calling function be be called
func (*Command) AddCommand ¶
AddCommand adds a new subcommand to this command
func (*Command) PersistentFlags ¶
PersistentFlags returns the persistent FlagSet for this command
type Handler ¶
type Handler struct {
Setupper
}
Handler is responsible for executing a user command. Before the command is run the Setupper is called to build the new command. The command is the executed. This allows the setup stage to capture flag information that is needed when the command itself is execture
func (*Handler) ProcessMessage ¶
func (h *Handler) ProcessMessage(ctx context.Context, w hugot.ResponseWriter, m *hugot.Message) error
ProcessMessage implements hugot.Handler for the command handler
type RunFunc ¶
type RunFunc func(ctx context.Context, w hugot.ResponseWriter, msg *hugot.Message, args []string) error
RunFunc is a specification for a function to be run in response to a user executing a command. msg is the original message, args is the set of arguments. And flags required should be setup during Setup dunction for the handler
type Set ¶
Set is a collection of command to be run by a mux.Mux
func (Set) ProcessMessage ¶
ProcessMessage implements the hugot.Handler interface for a Set
type SetupFunc ¶
SetupFunc takes a Command and is expected to configure it to provide some command functionality
func (SetupFunc) CommandSetup ¶
CommandSetup you to use a CommandSetupFunc directly as a Handler
Directories ¶
Path | Synopsis |
---|---|
Package ping provides a handler that replies to any message sent
|
Package ping provides a handler that replies to any message sent |
Package testcli provides an example Command handler with nested command handling.
|
Package testcli provides an example Command handler with nested command handling. |
Package uptime provides a handler that replies to any message sent
|
Package uptime provides a handler that replies to any message sent |