Documentation ¶
Index ¶
Constants ¶
const ( // HelpOpcode is the opcode for the help command. HelpOpcode string = "help" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandInfo ¶
type CommandInfo struct {
// contains filtered or unexported fields
}
CommandInfo represents a console command.
func MakeHelpCommand ¶ added in v0.3.5
func MakeHelpCommand(console *Console) (*CommandInfo, error)
MakeHelpCommand is a function that creates a help command for a console.
The help command, when run, returns as the first value a slice of []*ContentBox.MultilineText representing the list of available commands according to FString formatting.
Parameters:
- flagMap: A map of string keys to any values representing the arguments passed to the command.
Returns:
- *CommandInfo: The help command.
- error: An error of type *Errors.ErrInvalidParameter if the console is nil.
func NewCommandInfo ¶
func NewCommandInfo(description [][]string, fn ConsoleFunc, args []string) *CommandInfo
NewCommandInfo is a function that creates a new command info.
Parameters:
- description: The description of the command.
- fn: The function to call when the command is executed.
- args: A slice of string representing the arguments accepted by the command. Order matters.
Returns:
- *CommandInfo: The new command info.
func (*CommandInfo) FString ¶ added in v0.3.5
func (inf *CommandInfo) FString(trav *fsp.Traversor) error
FString generates a formatted string representation of a CommandInfo.
Format:
<description> Arguments: <arg 1> <arg 2> ...
or:
<description> Arguments: [No arguments available]
Parameters:
- trav: The traversor to use for the CommandInfo.
Returns:
- error: An error if the printing fails.
Behaviors:
- <description> is printed according to the DocumentPrinter.
- If trav is nil, the function will do nothing.
func (*CommandInfo) ParseArgs ¶
func (inf *CommandInfo) ParseArgs(args []string) (map[string]any, error)
ParseArgs is a function that parses the arguments for a command.
Parameters:
- args: A slice of strings representing the arguments passed to the command.
Returns:
- map[string]any: A map of string keys to any values representing the arguments parsed by the command.
- error: An error if the command fails.
Errors:
- *ErrMissingArgument: If an argument is missing.
- *ErrArgumentNotRecognized: If an argument is not recognized.
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
CommandInfo represents a console command.
func NewConsole ¶
func NewConsole() *Console
NewConsole is a function that creates a new console.
Returns:
- *Console: The new console.
func (*Console) AddCommand ¶
func (c *Console) AddCommand(name string, info *CommandInfo)
AddCommand adds a command to the console.
Parameters:
- name: The name of the command.
- info: The information about the command.
func (*Console) ParseArgs ¶
func (c *Console) ParseArgs(args []string) (*ParsedCommand, error)
ParseArgs parses the arguments for a command.
Parameters:
- args: A slice of strings representing the arguments passed to the command.
Returns:
- *ParsedCommand: The parsed command.
- error: An error if the command fails.
type ConsoleFunc ¶
ConsoleFunc is a function type that represents a callback function for a console command.
Parameters:
- flagMap: A map of string keys to any values representing the arguments passed to the command.
Returns:
- any: The result of the command. (if any)
- error: An error if the command fails.
type ErrArgumentNotRecognized ¶ added in v0.3.5
type ErrArgumentNotRecognized struct { // Value is the value of the unrecognized argument. Value string }
ErrArgumentNotRecognized is an error that is returned when an argument is not recognized.
func NewErrArgumentNotRecognized ¶ added in v0.3.5
func NewErrArgumentNotRecognized(value string) *ErrArgumentNotRecognized
NewErrArgumentNotRecognized creates a new ErrArgumentNotRecognized.
Parameters:
- value: The value of the unrecognized argument.
Returns:
- *ErrArgumentNotRecognized: The new ErrArgumentNotRecognized.
func (*ErrArgumentNotRecognized) Error ¶ added in v0.3.5
func (e *ErrArgumentNotRecognized) Error() string
Error returns the error message: "argument <value> is not recognized".
Returns:
- string: The error message.
type ErrMissingArgument ¶ added in v0.3.5
type ErrMissingArgument struct { // Name is the name of the missing argument. Name string }
ErrMissingArgument is an error that is returned when a required argument is missing.
func NewErrMissingArgument ¶ added in v0.3.5
func NewErrMissingArgument(name string) *ErrMissingArgument
NewErrMissingArgument creates a new ErrMissingArgument.
Parameters:
- name: The name of the missing argument.
Returns:
- *ErrMissingArgument: The new ErrMissingArgument.
func (*ErrMissingArgument) Error ¶ added in v0.3.5
func (e *ErrMissingArgument) Error() string
Error returns the error message: "argument <name> is required".
Returns:
- string: The error message.
type ParsedCommand ¶
type ParsedCommand struct {
// contains filtered or unexported fields
}
ParsedCommand represents a parsed command.
func NewParsedCommand ¶
func NewParsedCommand(command string, flagMap map[string]any, fn ConsoleFunc) *ParsedCommand
NewParsedCommand creates a new ParsedCommand.
Parameters:
- command: The name of the command.
- flagMap: A map of flags and their values.
- fn: The function to execute.
Returns:
- *ParsedCommand: The new ParsedCommand.
func (*ParsedCommand) Execute ¶
func (pc *ParsedCommand) Execute() (any, error)
Execute executes the command with the given flags.
Returns:
- error: An error if the command failed to execute.
func (*ParsedCommand) GetCommand ¶
func (pc *ParsedCommand) GetCommand() string
GetCommand returns the name of the command.
Returns:
- string: The name of the command.