Documentation
¶
Overview ¶
Package cli provides helpers for building CLI applications with go-service.
This package contains wiring and helpers around the CLI application framework used by this module.
Start with `Application`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // FS is the filesystem used for CLI configuration lookup. FS = os.NewFS() // Name is the CLI application name derived from the environment. Name = env.NewName(FS) // Version is the CLI application version derived from the environment. Version = env.NewVersion() )
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application is a CLI application composed of subcommands.
func NewApplication ¶
func NewApplication(register RegisterFunc, opts ...ApplicationOption) *Application
NewApplication constructs an Application and invokes register to add commands.
func (*Application) AddClient ¶
func (a *Application) AddClient(name, description string, opts ...Option) *Command
AddClient adds a subcommand that runs a client with Fx lifecycle wiring.
func (*Application) AddServer ¶
func (a *Application) AddServer(name, description string, opts ...Option) *Command
AddServer adds a subcommand that runs a server with Fx lifecycle wiring.
func (*Application) ExitOnError ¶
func (a *Application) ExitOnError(ctx context.Context)
ExitOnError runs the application and exits with status 1 if Run returns an error.
type ApplicationOption ¶
type ApplicationOption interface {
// contains filtered or unexported methods
}
ApplicationOption configures Application creation.
func WithApplicationExit ¶
func WithApplicationExit(exiter ExitFunc) ApplicationOption
WithApplicationExit sets the exit function used by Application.
type Command ¶
Command wraps a FlagSet and provides Fx wiring for CLI subcommands.
func NewCommand ¶ added in v2.66.0
NewCommand creates a new command with the given name.
type Commander ¶
type Commander interface {
// AddServer adds a server subcommand.
AddServer(name, description string, opts ...Option) *Command
// AddClient adds a client subcommand.
AddClient(name, description string, opts ...Option) *Command
}
Commander allows registering CLI subcommands.
type ExitFunc ¶ added in v2.105.0
type ExitFunc = func(code int)
ExitFunc is invoked when the application decides to exit.
type RegisterFunc ¶
type RegisterFunc = func(commander Commander)
RegisterFunc registers commands on a Commander.