Documentation
¶
Index ¶
- Variables
- type App
- func (app *App) AddApp(subApp *App)
- func (app *App) AddCommand(cmd *Command)
- func (app *App) Alias(name string) *App
- func (app *App) Run(args ...string) error
- func (app *App) RunAndExit(args ...string)
- func (app *App) RunContext(ctx context.Context, args ...string) error
- func (app *App) RunContextAndExit(ctx context.Context, args ...string)
- func (app *App) SetConfig(config Config)
- type Command
- func (cmd *Command) Alias(name string) *Command
- func (cmd *Command) Run(args ...string) error
- func (cmd *Command) RunAndExit(args ...string)
- func (cmd *Command) RunContext(ctx context.Context, args ...string) error
- func (cmd *Command) RunContextAndExit(ctx context.Context, args ...string)
- func (cmd *Command) SetConfig(config Config)
- type Config
- type Defaulter
- type Runner
Constants ¶
This section is empty.
Variables ¶
var (
ErrCommandNotFound = errors.New("Command not found")
)
var (
ErrInvalidArgument = errors.New("invalid argument")
)
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App represents a CLI application that can contain commands and sub-applications.
func NewApp ¶
NewApp creates a new App with the given name and description, and initializes it with the default configuration.
func (*App) AddApp ¶
AddApp adds a sub-application to the application. If the sub-application is nil, it is ignored.
func (*App) AddCommand ¶
AddCommand adds a command to the application. If the command is nil, it is ignored.
func (*App) Alias ¶
Alias adds an alias for the application. If the alias name is empty, it is ignored.
func (*App) RunAndExit ¶
RunAndExit executes the application with a background context and the given arguments and exits the process with code 1 if an error occurs.
func (*App) RunContext ¶ added in v0.1.0
RunContext executes the application with the given context and arguments. It first checks if the arguments indicate that the help message should be shown, then it tries to find a matching command or sub-application to execute. If no matching command or sub-application is found, it returns an error.
func (*App) RunContextAndExit ¶ added in v0.1.0
RunContextAndExit executes the application with the given context and arguments and exits the process with code 1 if an error occurs.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a command in the CLI application, including its name, description, handler function, argument specifications, and configuration.
func MustNewCommand ¶ added in v0.1.0
MustNewCommand is a helper function that creates a new Command and panics if an error occurs. It is useful for cases where the command definition is static and should not fail at runtime.
func MustUseCommand ¶ added in v0.1.0
MustUseCommand is a helper function that creates a new Command based on a Runner type and panics if an error occurs. It is useful for cases where the command definition is static and should not fail at runtime.
func NewCommand ¶
NewCommand creates a new Command with the given name, description, and handler function. The handler function can be any function that takes zero or more arguments and returns an error.
func UseCommand ¶
UseCommand creates a new Command based on a Runner type. It uses reflection to create a handler function that calls the Run method of the Runner, and it generates argument specifications based on the fields of the Runner struct.
func (*Command) Alias ¶
Alias adds an alias for the command. If the alias name is empty, it is ignored.
func (*Command) RunAndExit ¶
RunAndExit executes the command with a background context and the given arguments and exits the program with a non-zero status code if an error occurs.
func (*Command) RunContext ¶ added in v0.1.0
RunContext executes the command with the given context and arguments.
func (*Command) RunContextAndExit ¶ added in v0.1.0
RunContextAndExit executes the command with the given context and arguments and exits the program with a non-zero status code if an error occurs.
type Config ¶
type Config struct {
// Log is the destination for log output. By default, it is set to os.Stdout.
Log io.Writer
// ErrorLog is the destination for error output. By default, it is set to os.Stderr.
ErrorLog io.Writer
// contains filtered or unexported fields
}
Config represents the configuration for an application or command, including settings for log output and error output.