Documentation
¶
Overview ¶
Provides several types for managing multiple commands within a single application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command interface { // Returns the command's name; essentially it's identifier GetName() string // Prints usage information PrintUsage() // Runs the command using the provided args and returns any error Run(args []string) error }
The interface definition of a command. Any type that implements the interface can be used by the runner.
type CommandBase ¶
type CommandBase struct { // The name for command. Used by the GetName function Name string // The description of the command's usage. Used by the PrintUsage function Description string // The flag set for the command. Please use NewCommandBase to initialize correctly Flags *flag.FlagSet }
A base struct definition for a command. Provides default implementations for some command interface methods.
func NewCommandBase ¶
func NewCommandBase(name string, desc string) CommandBase
Creates a new command base; mostly used when creating child commands. Additionally sets a custom usage function for flag set.
func (CommandBase) GetName ¶
func (cmd CommandBase) GetName() string
Command interface implementation. Returns the Name field.
func (CommandBase) PrintUsage ¶
func (cmd CommandBase) PrintUsage()
Command interface implementation. Prints usage using the command's Name and Description fields.
type ConfigCommand ¶ added in v1.2.0
type ConfigCommand[T config.Config] struct { ConfigCommandBase[T] }
Command for performing operations with the config file.
func NewConfigCommand ¶ added in v1.2.0
func NewConfigCommand[T config.Config]() ConfigCommand[T]
Creates a new config command.
func (ConfigCommand[T]) Run ¶ added in v1.2.0
func (cmd ConfigCommand[T]) Run(args []string) error
Runs the config commands. Run with -h for details.
type ConfigCommandBase ¶ added in v1.2.0
type ConfigCommandBase[T config.Config] struct { CommandBase // contains filtered or unexported fields }
func NewConfigCommandBase ¶ added in v1.2.0
func NewConfigCommandBase[T config.Config](name, desc string) ConfigCommandBase[T]
func (ConfigCommandBase[T]) LoadConfig ¶ added in v1.2.0
func (cmd ConfigCommandBase[T]) LoadConfig() (*T, error)
type Runner ¶
type Runner struct { // The map of commands. Please use NewRunner to initialize correctly Commands map[string]Command }
Runner stores multiple commands and provides methods for running by name.
func (Runner) ListCommands ¶
func (r Runner) ListCommands()
Print the usage for all commands to the console.