Documentation
¶
Index ¶
- func Run(root any, opts ...AppOption) error
- type AfterRunner
- type App
- func (a *App) AddCommand(name string, cmd *parser.CommandNode)
- func (a *App) GenBashCompletion(w io.Writer) error
- func (a *App) GenFishCompletion(w io.Writer) error
- func (a *App) GenZshCompletion(w io.Writer) error
- func (a *App) Reload() error
- func (a *App) Run() (runErr error)
- func (a *App) SetContext(ctx context.Context)
- func (a *App) SetName(name string)
- func (a *App) SetTranslator(tr help.Translator)
- func (a *App) SetVersion(v string)
- type AppOption
- type Base
- type BeforeRunner
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AfterRunner ¶
type AfterRunner interface {
After() error
}
AfterRunner is an interface for commands that run after the main run.
type App ¶ added in v2.0.3
type App struct {
RootNode *parser.CommandNode
Translator help.Translator
Container *di.Container
Validator *validation.Validator
// contains filtered or unexported fields
}
App represents a CLI application.
func New ¶ added in v2.0.3
New creates a new App from a root struct.
Example:
app, err := cli.New(&CLI{}, cli.WithVersion("1.0.0"))
func (*App) AddCommand ¶ added in v2.0.3
func (a *App) AddCommand(name string, cmd *parser.CommandNode)
AddCommand adds a dynamic command to the application.
func (*App) GenBashCompletion ¶ added in v2.1.0
GenBashCompletion writes a bash completion script for the app.
func (*App) GenFishCompletion ¶ added in v2.1.0
GenFishCompletion writes a fish completion script for the app.
func (*App) GenZshCompletion ¶ added in v2.1.0
GenZshCompletion writes a zsh completion script for the app.
func (*App) Reload ¶ added in v2.0.4
Reload re-parses the root struct to pick up dynamic changes (e.g. map entries).
Example:
err := app.Reload()
func (*App) SetContext ¶ added in v2.1.0
SetContext sets the context for the application.
func (*App) SetTranslator ¶ added in v2.0.4
func (a *App) SetTranslator(tr help.Translator)
SetTranslator sets the translator for the application.
func (*App) SetVersion ¶ added in v2.1.0
SetVersion sets the version string for the application.
type AppOption ¶ added in v2.2.0
AppOption is a functional option for App configuration.
func WithContainer ¶ added in v2.2.0
WithContainer sets the DI container for dependency injection in commands.
func WithContext ¶ added in v2.2.0
WithContext sets the application context.
func WithPanicRecovery ¶ added in v2.2.0
func WithPanicRecovery() AppOption
WithPanicRecovery enables panic recovery in Run.
func WithTranslator ¶ added in v2.2.0
func WithTranslator(tr help.Translator) AppOption
WithTranslator sets the help translator.
func WithValidator ¶ added in v2.2.0
func WithValidator(validator *validation.Validator) AppOption
WithValidator sets the struct validator for command validation.
func WithVersion ¶ added in v2.2.0
WithVersion sets the application version.
type Base ¶
type Base struct {
Logger log.Logger `internal:"ignore"`
Ctx context.Context `internal:"ignore"`
Container *di.Container `internal:"ignore"`
}
Base is a struct that can be embedded in commands to provide common functionality.
type BeforeRunner ¶
type BeforeRunner interface {
Before() error
}
BeforeRunner is an interface for commands that run before the main run.