Documentation ¶
Overview ¶
Package CnsPanel provides a structure and functions for handling console command flags.
Package CnsPanel provides a structure and functions for handling console command flags.
Package CnsPanel provides a structure and functions for handling console command flags.
Index ¶
- Variables
- func NoArgumentParser(args []string) ([]any, error)
- func NoCommandCallback(args map[string]map[string][]any) (any, error)
- func NoFlagCallback(argMap map[string][]any) (map[string][]any, error)
- type ArgInfo
- type ArgumentParserFunc
- type CommandCallbackFunc
- type CommandInfo
- func (ci *CommandInfo) Equals(other uc.Equaler) bool
- func (inf *CommandInfo) Evaluator() evalSlc.LeafEvaluater[string, *resultBranch, int, []*FlagParseResult]
- func (cci *CommandInfo) FString(trav *ffs.Traversor, opts ...ffs.Option) error
- func (inf *CommandInfo) GetCallback() CommandCallbackFunc
- func (inf *CommandInfo) GetDescription() []string
- func (inf *CommandInfo) GetFlag(name string) *FlagInfo
- func (inf *CommandInfo) GetFlags() []*FlagInfo
- func (inf *CommandInfo) GetOpcode() string
- func (inf *CommandInfo) HasFlag(name string) bool
- func (inf *CommandInfo) Parse(branches []*resultBranch, args []string) ([]*uc.Pair[*ParsedCommand, error], error)
- type DescriptionPrinter
- type ErrFormatError
- type FlagCallbackFunc
- type FlagInfo
- func (inf *FlagInfo) Equals(other uc.Equaler) bool
- func (inf *FlagInfo) Evaluator() evalSlc.LeafEvaluater[string, *FlagParseResult, *ArgInfo, []*resultArg]
- func (cfi *FlagInfo) FString(trav *ffs.Traversor, opts ...ffs.Option) error
- func (inf *FlagInfo) GetArguments() []*ArgInfo
- func (inf *FlagInfo) GetName() string
- func (inf *FlagInfo) IsRequired() bool
- func (flag *FlagInfo) Parse(branches []*FlagParseResult, args []string) ([]*FlagParseResult, error)
- type FlagParseResult
- type ParsedCommand
Constants ¶
This section is empty.
Variables ¶
var ( ResultBranchSortFunc uts.SortFunc[*resultBranch] FlagParseResultSortFunc uts.SortFunc[*FlagParseResult] )
Functions ¶
func NoArgumentParser ¶
NoArgumentParser is a default argument parser function that returns the string as is.
Parameters:
- string: The string to parse.
Returns:
- any: The string as is.
- error: nil
func NoCommandCallback ¶
NoCommandCallback is a default callback function for a console command when no callback is provided.
Parameters:
- args: A map of string keys to any values representing the arguments passed to the command.
Returns:
- error: nil
- any: nil
func NoFlagCallback ¶
NoFlagCallback is a default callback function for a console command flag when no callback is provided.
Parameters:
- args: A slice of strings representing the arguments passed to the flag.
Returns:
- map[string]any: A map of string keys to any values representing the parsed arguments.
- error: nil
Types ¶
type ArgInfo ¶
type ArgInfo struct {
// contains filtered or unexported fields
}
ArgInfo represents an argument of a flag.
func NewArgument ¶
func NewArgument(format string, fn ArgumentParserFunc) (*ArgInfo, error)
func (*ArgInfo) Equals ¶
Equals checks if the argument is equal to another argument.
Two arguments are equal iff their names are equal.
Parameters:
- other: The other argument to compare.
Returns:
- bool: true if the arguments are equal, false otherwise.
func (*ArgInfo) GetName ¶
GetName returns the name of the argument.
Returns:
- string: The name of the argument.
type ArgumentParserFunc ¶
ArgumentParserFunc is a function type that represents a function that parses a string argument.
Parameters:
- string: The string to parse.
Returns:
- any: The parsed value.
type CommandCallbackFunc ¶
CommandCallbackFunc is a function type that represents a callback function for a console command.
Parameters:
- args: A map of string keys to any values representing the arguments passed to the command.
Returns:
- error: An error if the command fails.
- any: The result of the command. (if any)
type CommandInfo ¶
type CommandInfo struct {
// contains filtered or unexported fields
}
CommandInfo represents a console command.
func NewCommandInfo ¶
func NewCommandInfo(name string, description []string, fn CommandCallbackFunc, flagInfos []*FlagInfo) (*CommandInfo, error)
NewCommandInfo creates a new CommandInfo with the provided command name and callback function.
Parameters:
- name: The name of the command.
- description: The description of the command.
- callback: The function to call when the command is executed.
Returns:
- *CommandInfo: A pointer to the new CommandInfo.
Behaviors:
- If callback is nil, NoCommandCallback is used.
func (*CommandInfo) Equals ¶
func (ci *CommandInfo) Equals(other uc.Equaler) bool
Equals checks if the command is equal to another command.
Two commands are equal iff their names are equal.
Parameters:
- other: The other command to compare.
Returns:
- bool: true if the commands are equal, false otherwise.
func (*CommandInfo) Evaluator ¶
func (inf *CommandInfo) Evaluator() evalSlc.LeafEvaluater[string, *resultBranch, int, []*FlagParseResult]
Evaluator implements the Evaluable interface.
func (*CommandInfo) FString ¶
FString generates a formatted string representation of a CommandInfo.
Parameters:
- indentLevel: The level of indentation to use for the CommandInfo.
Returns:
- []string: A slice of strings representing the CommandInfo.
Format:
Description: // <description> Flags: - <flag 1>: // <description> - <flag 2>: // <description> // ...
func (*CommandInfo) GetCallback ¶
func (inf *CommandInfo) GetCallback() CommandCallbackFunc
GetCallback returns the callback function of a CommandInfo.
Returns:
- CommandCallbackFunc: The callback function of the CommandInfo.
Behaviors:
- Never returns nil.
func (*CommandInfo) GetDescription ¶
func (inf *CommandInfo) GetDescription() []string
GetDescription returns the description of a CommandInfo.
Returns:
- *fsd.Document: The description of the CommandInfo.
func (*CommandInfo) GetFlag ¶
func (inf *CommandInfo) GetFlag(name string) *FlagInfo
GetFlag returns the FlagInfo with the provided name.
Parameters:
- name: The name of the flag to get.
Returns:
- *FlagInfo: The FlagInfo with the provided name. Nil if not found.
func (*CommandInfo) GetFlags ¶
func (inf *CommandInfo) GetFlags() []*FlagInfo
GetFlags returns the flags of a CommandInfo.
Returns:
- []*FlagInfo: The flags of the CommandInfo.
Behaviors:
- Modifying the returned slice will affect the CommandInfo.
func (*CommandInfo) GetOpcode ¶
func (inf *CommandInfo) GetOpcode() string
GetOpcode returns the name of a CommandInfo.
Returns:
- string: The name of the CommandInfo.
func (*CommandInfo) HasFlag ¶
func (inf *CommandInfo) HasFlag(name string) bool
HasFlag checks if a CommandInfo has a flag with the provided name.
Parameters:
- name: The name of the flag to check.
Returns:
- bool: True if the flag exists, false otherwise.
func (*CommandInfo) Parse ¶
func (inf *CommandInfo) Parse(branches []*resultBranch, args []string) ([]*uc.Pair[*ParsedCommand, error], error)
ParseArguments parses the provided command line arguments and returns a ParsedCommand ready to be executed.
Errors:
- *ue.ErrInvalidParameter: No arguments provided.
- *ErrCommandNotFound: Command not found.
- *ErrParsingFlags: Error parsing flags.
Parameters:
- args: The command line arguments to parse. Without the executable name.
Returns:
- *ParsedCommand: A pointer to the parsed command.
- error: An error, if any.
type DescriptionPrinter ¶
type DescriptionPrinter struct {
// contains filtered or unexported fields
}
func NewDescriptionPrinter ¶
func NewDescriptionPrinter(lines []string) *DescriptionPrinter
type ErrFormatError ¶
type ErrFormatError struct { // Reason is the reason for the error. Reason error }
ErrFormatError is an error type that is returned when a format error occurs.
func NewErrFormatError ¶
func NewErrFormatError(reason error) *ErrFormatError
NewErrFormatError creates a new ErrFormatError error.
Parameters:
- reason: The reason for the error.
Returns:
- *ErrFormatError: A pointer to the new error.
func (*ErrFormatError) Error ¶
func (e *ErrFormatError) Error() string
Error returns the error message: "format error: <reason>".
Returns:
- string: The error message.
Behaviors:
- If Reason is nil, the error message is: "format is invalid" instead.
type FlagCallbackFunc ¶
FlagCallbackFunc is a function type that represents a callback function for a console command flag.
Parameters:
- argMap: A map of string keys to any values representing the arguments passed to the flag.
Returns:
- map[string]any: A map of string keys to any values representing the parsed arguments.
- error: An error if the flag fails.
type FlagInfo ¶
type FlagInfo struct {
// contains filtered or unexported fields
}
FlagInfo represents a flag for a console command.
func NewFlagInfo ¶
func (*FlagInfo) Equals ¶
Equals checks if the flag is equal to another flag.
Two flags are equal iff their names are equal.
Parameters:
- other: The other flag to compare.
Returns:
- bool: true if the flags are equal, false otherwise.
func (*FlagInfo) Evaluator ¶
func (inf *FlagInfo) Evaluator() evalSlc.LeafEvaluater[string, *FlagParseResult, *ArgInfo, []*resultArg]
Evaluator implements the Evaluable interface.
func (*FlagInfo) FString ¶
FString generates a formatted string representation of a FlagInfo.
Parameters:
- indentLevel: The level of indentation to use for the FlagInfo.
Returns:
- []string: A slice of strings representing the FlagInfo.
Format:
Arguments: <arg1> <arg2> ... Description: // <description> Required: <Yes/No>
func (*FlagInfo) GetArguments ¶
GetArguments returns the arguments of a FlagInfo.
Returns:
- []*Argument: A slice of pointers to the arguments.
Behaviors:
- No nil values are returned.
- Modifying the returned slice will affect the FlagInfo.
func (*FlagInfo) GetName ¶
GetName returns the name of a FlagInfo.
Returns:
- string: The name of the FlagInfo.
func (*FlagInfo) IsRequired ¶
IsRequired returns whether a FlagInfo is required.
Returns:
- bool: A boolean indicating whether the FlagInfo is required.
func (*FlagInfo) Parse ¶
func (flag *FlagInfo) Parse(branches []*FlagParseResult, args []string) ([]*FlagParseResult, error)
Parse parses the provided arguments into a map of parsed arguments.
Parameters:
- args: The arguments to parse.
Returns:
- map[string]any: A map of the parsed arguments.
- error: An error if the arguments are invalid.
type FlagParseResult ¶
type FlagParseResult struct {
// contains filtered or unexported fields
}
FlagParseResult represents the result of parsing a flag.
func NewFlagParseResult ¶
func NewFlagParseResult() *FlagParseResult
NewFlagParseResult creates a new FlagParseResult with the given arguments, index, and ignorable boolean.
Parameters:
- argMap: A map of argument names to their values.
- argsDone: A list of arguments that have been parsed so far.
Returns:
- *FlagParseResult: A pointer to the new FlagParseResult.
func (*FlagParseResult) Copy ¶
func (fpr *FlagParseResult) Copy() uc.Copier
Copier implements the Copier interface.
func (*FlagParseResult) GetArgumentsDone ¶
func (fpr *FlagParseResult) GetArgumentsDone() []string
GetArgumentsDone returns the arguments that have been parsed so far.
Returns:
- []string: The arguments that have been parsed so far.
func (*FlagParseResult) GetResult ¶
func (fpr *FlagParseResult) GetResult() map[string][]any
GetResult returns the parsed arguments.
Returns:
- map[string][]any: The parsed arguments.
type ParsedCommand ¶
type ParsedCommand struct {
// contains filtered or unexported fields
}
ParsedCommand represents a parsed console command.
func (*ParsedCommand) Execute ¶
func (pc *ParsedCommand) Execute() (any, error)
Execute executes the callback function for the parsed command.
Returns:
- any: The result of the callback function.
- error: An error if the callback function fails.
func (*ParsedCommand) GetName ¶
func (pc *ParsedCommand) GetName() string
GetName returns the name of the command.
Returns:
- string: The name of the command.