Common

package
v0.2.41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoArgumentParser

func NoArgumentParser(s string) (any, error)

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

func NoCommandCallback(args ArgumentsMap) error

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

Types

type ArgumentParserFunc

type ArgumentParserFunc func(string) (any, error)

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 ArgumentsMap

type ArgumentsMap map[string]any

ArgumentsMap is a map of string keys to any values representing the arguments passed to a command.

Key: The name of the argument. Value: The value of the argument.

func NoFlagCallback

func NoFlagCallback(argMap ArgumentsMap) (ArgumentsMap, error)

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:

  • ArgumentsMap: A map of string keys to any values representing the parsed arguments.
  • error: nil

type CommandCallbackFunc

type CommandCallbackFunc func(args ArgumentsMap) error

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.

type ErrCommandNotFound

type ErrCommandNotFound struct {
	// The command that was not found.
	Command string
}

ErrCommandNotFound represents an error where a command is not found.

func NewErrCommandNotFound

func NewErrCommandNotFound(command string) *ErrCommandNotFound

NewErrCommandNotFound creates a new ErrCommandNotFound with the provided command.

Parameters:

  • command: The command that was not found.

Returns:

  • *ErrCommandNotFound: A pointer to the new ErrCommandNotFound.

func (*ErrCommandNotFound) Error

func (e *ErrCommandNotFound) Error() string

Error returns the error message for an ErrCommandNotFound.

Returns:

  • string: The error message.

type ErrFewArguments

type ErrFewArguments struct{}

ErrFewArguments represents an error where not enough arguments are provided.

func NewErrFewArguments

func NewErrFewArguments() *ErrFewArguments

NewErrFewArguments creates a new ErrFewArguments.

Returns:

  • *ErrFewArguments: A pointer to the new ErrFewArguments.

func (*ErrFewArguments) Error

func (e *ErrFewArguments) Error() string

Error returns the error message for an ErrFewArguments.

Returns:

  • string: The error message.

type ErrParsingFlags

type ErrParsingFlags struct {
	// Name is the flag that could not be parsed.
	Name string

	// Reason is the reason the flag could not be parsed.
	Reason error
}

ErrParsingFlags represents an error where flags could not be parsed.

func NewErrParsingFlags

func NewErrParsingFlags(name string, reason error) *ErrParsingFlags

NewErrParsingFlags creates a new ErrParsingFlags with the provided name and reason.

Parameters:

  • name: The flag that could not be parsed.
  • reason: The reason the flag could not be parsed.

Returns:

  • *ErrParsingFlags: A pointer to the new ErrParsingFlags.

func (*ErrParsingFlags) Error

func (e *ErrParsingFlags) Error() string

Error returns the error message for an ErrParsingFlags.

Returns:

  • string: The error message.

func (*ErrParsingFlags) Unwrap

func (e *ErrParsingFlags) Unwrap() error

Unwrap returns the reason the flags could not be parsed.

Returns:

  • error: The reason the flags could not be parsed.

type ErrUnknownFlag

type ErrUnknownFlag struct {
	// The flag that is unknown.
	Flag string
}

ErrUnknownFlag represents an error where an unknown flag is provided.

func NewErrUnknownFlag

func NewErrUnknownFlag(flag string) *ErrUnknownFlag

NewErrUnknownFlag creates a new ErrUnknownFlag.

Returns:

  • *ErrUnknownFlag: A pointer to the new ErrUnknownFlag.

func (*ErrUnknownFlag) Error

func (e *ErrUnknownFlag) Error() string

Error returns the error message: "<flag> is not a known flag".

Returns:

  • string: The error message.

type FlagCallbackFunc

type FlagCallbackFunc func(argMap ArgumentsMap) (ArgumentsMap, error)

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:

  • ArgumentsMap: A map of string keys to any values representing the parsed arguments.
  • error: An error if the flag fails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL