Documentation
¶
Index ¶
- Constants
- func GenDocsCommand(ec *ecctx.ExecutionContext) *cobra.Command
- type InitFunc
- type RootCommandBuilder
- type SubCommandBuilder
- func (b *SubCommandBuilder[T]) Build() *cobra.Command
- func (b *SubCommandBuilder[T]) WithExample(example string) *SubCommandBuilder[T]
- func (b *SubCommandBuilder[T]) WithGroupID(group string) *SubCommandBuilder[T]
- func (b *SubCommandBuilder[T]) WithLongDesc(desc string) *SubCommandBuilder[T]
- func (b *SubCommandBuilder[T]) WithShortDesc(desc string) *SubCommandBuilder[T]
- type SubCommandRunner
- type TestRunner
Constants ¶
const ( GroupBase = "group-base" GroupOther = "group-other" )
Variables ¶
This section is empty.
Functions ¶
func GenDocsCommand ¶ added in v0.8.1
func GenDocsCommand(ec *ecctx.ExecutionContext) *cobra.Command
Types ¶
type RootCommandBuilder ¶ added in v0.8.1
type RootCommandBuilder struct {
// contains filtered or unexported fields
}
func NewRootCommand ¶
func NewRootCommand(ec *context.ExecutionContext) *RootCommandBuilder
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 (*RootCommandBuilder) Build ¶ added in v0.8.1
func (b *RootCommandBuilder) Build() *cobra.Command
Build builds the root command
func (*RootCommandBuilder) WithInitFunc ¶ added in v0.8.1
func (b *RootCommandBuilder) WithInitFunc(fn InitFunc) *RootCommandBuilder
WithInitFunc adds an init function to the root command This sets the PersistentPreRunE function of the command
func (*RootCommandBuilder) WithPersistentFlags ¶ added in v0.8.1
func (b *RootCommandBuilder) WithPersistentFlags(flags *pflag.FlagSet) *RootCommandBuilder
WithPreRunFunc adds persistent flags to the root command
type SubCommandBuilder ¶ added in v0.8.1
type SubCommandBuilder[T any] struct { // contains filtered or unexported fields }
SubCommandBuilder is a builder for a subcommand
func NewSubCommand ¶
func NewSubCommand[T any]( name string, runner SubCommandRunner[T], runnerArg T, ) *SubCommandBuilder[T]
NewSubCommand creates a new subcommand args can be used to pass arguments to the runner
func (*SubCommandBuilder[T]) Build ¶ added in v0.8.1
func (b *SubCommandBuilder[T]) Build() *cobra.Command
Build builds the subcommand
func (*SubCommandBuilder[T]) WithExample ¶ added in v0.8.1
func (b *SubCommandBuilder[T]) WithExample(example string) *SubCommandBuilder[T]
WithExample sets the example of the subcommand
func (*SubCommandBuilder[T]) WithGroupID ¶ added in v0.8.1
func (b *SubCommandBuilder[T]) WithGroupID(group string) *SubCommandBuilder[T]
WithGroupID sets the group id of the subcommand
func (*SubCommandBuilder[T]) WithLongDesc ¶ added in v0.8.1
func (b *SubCommandBuilder[T]) WithLongDesc(desc string) *SubCommandBuilder[T]
WithLongDesc sets the long description of the subcommand
func (*SubCommandBuilder[T]) WithShortDesc ¶ added in v0.8.1
func (b *SubCommandBuilder[T]) WithShortDesc(desc string) *SubCommandBuilder[T]
WithShortDesc sets the short description of the subcommand
type SubCommandRunner ¶
type SubCommandRunner[T any] interface { // Complete performs any setup or completion of arguments Complete(ctx context.Context, arg T) // Validate checks if the arguments are valid // Returns error if validation fails Validate(ctx context.Context, arg T) error // Run executes the command with the given arguments // Returns error if execution fails Run(ctx context.Context, arg T) error }
SubCommandRunner is an interface for a subcommand runner
type TestRunner ¶ added in v0.8.1
type TestRunner[T any] struct { CompleteFunc func(T) ValidateFunc func(T) error RunFunc func(T) error }
func (*TestRunner[T]) Complete ¶ added in v0.8.1
func (tr *TestRunner[T]) Complete(args T)
func (*TestRunner[T]) Run ¶ added in v0.8.1
func (tr *TestRunner[T]) Run(args T) error
func (*TestRunner[T]) Validate ¶ added in v0.8.1
func (tr *TestRunner[T]) Validate(args T) error