cmd

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GroupBase  = "group-base"
	GroupOther = "group-other"
)

Variables

This section is empty.

Functions

func Execute

func Execute(cmd *cobra.Command, appName, shortDesc, longDesc, version string) int

Execute runs the root command and returns the exit code

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

Types

type InitFunc

type InitFunc = func(cmd *cobra.Command, args []string) error

type SubCommandRunner

type SubCommandRunner interface {
	Complete(...any)
	Validate(...any) error
	Run(...any) error
}

SubCommandRunner is an interface for a subcommand runner These commands are the commands run in that order

Jump to

Keyboard shortcuts

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