Documentation ¶
Overview ¶
Package CMLine provides a structure and functions for handling console command flags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CMLine ¶ added in v0.2.7
type CMLine struct {
// contains filtered or unexported fields
}
CMLine represents a command line interface.
func NewCMLine ¶ added in v0.2.7
func NewCMLine(options ...CMLineOption) *CMLine
NewCMLine creates a new CMLine with the given options. If any errors occur while creating the commands, it panics with the error of the invalid option.
Parameters:
- options: The options to apply to the CMLine.
Returns:
- *CMLine: A pointer to the newly created CMLine.
func (*CMLine) FString ¶ added in v0.2.7
FString generates a formatted string representation of a CMLine. It includes the usage information, and the list of commands and their details.
Returns:
- string: A string representing the CMLine.
func (*CMLine) ParseCommandLine ¶ added in v0.2.7
ParseCommandLine parses the provided command line arguments and executes the corresponding command.
Panics with an error of type *ErrInvalidParameter if no arguments are provided, or with an error of type *ErrCallFailed if the ParseCommandLine function fails.
Parameters:
- args: The command line arguments to parse.
Returns:
- string: The name of the executed command.
- any: The result of the command.
type CMLineOption ¶ added in v0.2.7
CMLineOption is a function type that modifies CMLine.
Parameters:
- cm: The CMLine to modify.
Returns:
- error: An error if the modification fails.
func WithCommand ¶ added in v0.2.7
func WithCommand(name string, options ...CommandInfoOption) CMLineOption
WithCommand is a CMLineOption that adds a new command to a CMLine. It trims the space from the name. If the name is empty, it returns an error of type *ErrInvalidParameter.
Parameters:
- name: The name of the command.
- options: The options to apply to the command.
Returns:
- CMLineOption: A CMLineOption that adds a new command to a CMLine.
func WithDescription ¶ added in v0.2.7
func WithDescription(description ...string) CMLineOption
WithDescription is a CMLineOption that sets the description for a CMLine. It splits each line of the description by newline characters.
Parameters:
- description: The description to set.
Returns:
- CMLineOption: A CMLineOption that sets the description for a CMLine.
func WithExecutableName ¶ added in v0.2.7
func WithExecutableName(name string) CMLineOption
WithExecutableName is a CMLineOption that sets the executable name for a CMLine. It trims the space from the name. If the name is empty, it returns an error of type *ErrInvalidParameter.
Parameters:
- name: The name of the executable.
Returns:
- CMLineOption: A CMLineOption that sets the executable name for a CMLine.
type CommandInfoOption ¶ added in v0.2.7
type CommandInfoOption func(*ConsoleCommandInfo) error
CommandInfoOption is a function type that modifies ConsoleCommandInfo.
Parameters:
- command: The ConsoleCommandInfo to modify.
Returns:
- error: An error if the modification fails.
func WithCallback ¶ added in v0.2.7
func WithCallback(callback func(map[string]any) (any, error)) CommandInfoOption
WithCallback is a CommandInfoOption that sets the callback for a ConsoleCommandInfo. If the provided callback is nil, it returns an error of type *ErrInvalidParameter.
Parameters:
- callback: The function to call when the command is used.
Returns:
- CommandInfoOption: A CommandInfoOption that sets the callback for a ConsoleCommandInfo.
func WithCommandDescription ¶ added in v0.2.8
func WithCommandDescription(description ...string) CommandInfoOption
WithCommandDescription is a CommandInfoOption that sets the description for a ConsoleCommandInfo. It splits each line of the description by newline characters.
Parameters:
- description: The description to set.
Returns:
- CommandInfoOption: A CommandInfoOption that sets the description for a ConsoleCommandInfo.
func WithFlag ¶ added in v0.2.7
func WithFlag(name string, callback func(...string) (any, error), options ...FlagInfoOption) CommandInfoOption
WithFlag is a CommandInfoOption that adds a new flag to a ConsoleCommandInfo. It creates a new ConsoleFlagInfo with the provided name and callback, and applies the provided options to it. If the flag name is empty or the callback is nil, it returns an error of type *ErrInvalidParameter.
Parameters:
- name: The name of the flag.
- callback: The function to call when the flag is used.
- options: The options to apply to the flag.
Returns:
- CommandInfoOption: A CommandInfoOption that adds a new flag to a ConsoleCommandInfo.
type ConsoleCommandInfo ¶
type ConsoleCommandInfo struct {
// contains filtered or unexported fields
}
ConsoleCommandInfo represents a console command.
func (*ConsoleCommandInfo) FString ¶ added in v0.2.3
func (cci *ConsoleCommandInfo) FString(indentLevel int) string
FString generates a formatted string representation of a ConsoleCommandInfo. It includes the command name, description, usage information for each flag, and the list of flags and their details.
Panics if the indentLevel is less than 0.
Parameters:
- indentLevel: The level of indentation to use.
Returns:
- string: A string representing the ConsoleCommandInfo.
type ConsoleFlagInfo ¶
type ConsoleFlagInfo struct {
// contains filtered or unexported fields
}
ConsoleFlagInfo represents a flag for a console command.
func (*ConsoleFlagInfo) FString ¶ added in v0.2.3
func (cfi *ConsoleFlagInfo) FString(indentLevel int) string
FString generates a formatted string representation of a ConsoleFlagInfo, including the flag name, arguments, description, and whether it is required.
Panics if the indentLevel is less than 0.
Parameters:
- indentLevel: The level of indentation to use.
Returns:
- String: A string representing the ConsoleFlagInfo.
type FlagInfoOption ¶ added in v0.2.7
type FlagInfoOption func(*ConsoleFlagInfo)
FlagInfoOption is a function type that modifies ConsoleFlagInfo.
Parameters:
- ConsoleFlagInfo: The ConsoleFlagInfo to modify.
func WithArgs ¶ added in v0.2.7
func WithArgs(args ...string) FlagInfoOption
WithArgs is a FlagInfoOption that sets the arguments for a ConsoleFlagInfo. It trims the space from each argument and ignores empty arguments.
Parameters:
- args: The arguments to set.
Returns:
- FlagInfoOption: A FlagInfoOption that sets the arguments for a ConsoleFlagInfo.
func WithFlagDescription ¶ added in v0.2.8
func WithFlagDescription(description ...string) FlagInfoOption
WithFlagDescription is a FlagInfoOption that sets the description for a ConsoleFlagInfo. It splits each line of the description by newline characters.
Parameters:
- description: The description to set.
Returns:
- FlagInfoOption: A FlagInfoOption that sets the description for a ConsoleFlagInfo.
func WithRequired ¶ added in v0.2.7
func WithRequired(required bool) FlagInfoOption
WithRequired is a FlagInfoOption that sets whether a ConsoleFlagInfo is required.
Parameters:
- required: Whether the flag is required.
Returns:
- FlagInfoOption: A FlagInfoOption that sets whether a ConsoleFlagInfo is required.