Documentation
¶
Index ¶
- Constants
- func Execute(cmd *cobra.Command, appName, shortDesc, longDesc, version string) int
- func NewRootCommand(ec *context.ExecutionContext, initFunc InitFunc) *cobra.Command
- func NewSubCommand(name, shortDesc, longDesc, group string, runner SubCommandRunner, args ...any) *cobra.Command
- type InitFunc
- type SubCommandRunner
Constants ¶
const ( GroupBase = "group-base" GroupOther = "group-other" )
Variables ¶
This section is empty.
Functions ¶
func NewRootCommand ¶
func NewRootCommand(ec *context.ExecutionContext, initFunc InitFunc) *cobra.Command
NewRootCommand creates a new root command Use this function to create a new root command that is used to add subcommands
It supports the following features:
- Adding global flags to the command - Automatically reads configuration from the configuration file - Automatically reads configuration from environment variables - Automatically binds the configuration to the command's flags - Automatically sets the log level based on the configuration - Automatically sets the log format based on the configuration
It uses ec.AppName as the base name for the configuration file and environment variables initFunc is a function that is called before the command is executed It can be used to add more context or do other initializations
func NewSubCommand ¶
func NewSubCommand(name, shortDesc, longDesc, group string, runner SubCommandRunner, args ...any) *cobra.Command
NewSubCommand creates a new subcommand args are passed to the runner.Complete, runner.Validate and runner.Run methods it is up to the runner to decide how to use these arguments