Documentation
¶
Index ¶
- type Command
- func (c *Command) AddBoolFlag(name, shortName, usage string, defaultValue, allowArg bool) *bool
- func (c *Command) AddFlag(name, shortName, usage, defaultValue string, allowArg bool) *string
- func (c *Command) AddIntFlag(name, shortName, usage string, defaultValue int, allowArg bool) *int
- func (c *Command) GetEnv(key, defaultValue string) string
- func (c *Command) GetEnvBool(key string, defaultValue bool) bool
- func (c *Command) GetEnvInt(key string, defaultValue int) int
- func (c *Command) GetFlagBool(name string) bool
- func (c *Command) GetFlagInt(name string) int
- func (c *Command) GetFlagString(name string) string
- func (c *Command) PrintCommandHelp()
- func (c *Command) SetupLogger(name string)
- type RootFlags
- type RunFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Name is the name of the command.
Name string
// Usage is the short usage description of the command.
Usage string
// Description is the detailed description of the command.
Description string
// Flags are the command-line flags for the command.
Flags *flag.FlagSet
// Run is the function to execute when the command is invoked.
Run RunFunc
// SubCommands are the subcommands of the command.
SubCommands []*Command
// ArgFlags maps flag names to a boolean indicating if the flag allows an argument.
ArgFlags map[string]bool
// ShortFlagMap maps short flag names to their corresponding long flag names.
ShortFlagMap map[string]string
// Logger is an instance of the active logger.
Logger *log.DefaultLogger
// LogInfo is the function to log informational messages.
LogInfo func(format string, a ...any)
// LogWarning is the function to log warning messages.
LogWarning func(format string, a ...any)
// LogError is the function to log error messages.
LogError func(format string, a ...any)
// LogSuccess is the function to log success messages.
LogSuccess func(format string, a ...any)
}
Command represents a CLI command.
func (*Command) AddBoolFlag ¶
AddBoolFlag adds a boolean flag to the command.
Parameters:
- name: The name of the flag.
- usage: The usage description of the flag.
- allowArg: Whether the flag allows an argument.
Returns:
- A pointer to the boolean value of the flag.
func (*Command) AddFlag ¶
AddFlag adds a string flag to the command.
Parameters:
- name: The name of the flag.
- usage: The usage description of the flag.
- allowArg: Whether the flag allows an argument.
Returns:
- A pointer to the string value of the flag.
func (*Command) AddIntFlag ¶
AddIntFlag adds an integer flag to the command.
Parameters:
- name: The name of the flag.
- usage: The usage description of the flag.
- allowArg: Whether the flag allows an argument.
Returns:
- A pointer to the integer value of the flag.
func (*Command) GetEnv ¶
GetEnv retrieves the value of an environment variable.
Parameters:
- key: The name of the environment variable.
- defaultValue: The default value to return if the variable is not set.
Returns:
- The value of the environment variable, or the default value if not set.
func (*Command) GetEnvBool ¶
GetEnvBool retrieves the boolean value of an environment variable.
Parameters:
- key: The name of the environment variable.
- defaultValue: The default value to return if the variable is not set or not a boolean.
Returns:
- The boolean value of the environment variable, or the default value if not set or not a boolean.
func (*Command) GetEnvInt ¶
GetEnvInt retrieves the integer value of an environment variable.
Parameters:
- key: The name of the environment variable.
- defaultValue: The default value to return if the variable is not set or not an integer.
Returns:
- The integer value of the environment variable, or the default value if not set or not an integer.
func (*Command) GetFlagBool ¶
GetFlagBool retrieves the boolean value of a flag.
Parameters:
- name: The name of the flag.
Returns:
- The boolean value of the flag, or false if the flag does not exist.
func (*Command) GetFlagInt ¶
GetFlagInt retrieves the integer value of a flag.
Parameters:
- name: The name of the flag.
Returns:
- The integer value of the flag, or -1 if the flag does not exist or is not an integer.
func (*Command) GetFlagString ¶
GetFlagString retrieves the string value of a flag.
Parameters:
- name: The name of the flag.
Returns:
- The string value of the flag, or an empty string if the flag does not exist.
func (*Command) PrintCommandHelp ¶
func (c *Command) PrintCommandHelp()
PrintCommandHelp prints the help message for a single command.
func (*Command) SetupLogger ¶
setupLogger sets up the logger functions for the command.
Parameters:
- name: The name of the command.