cli

package
v2.286.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 9 Imported by: 13

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

View Source
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.

func (*Application) Run

func (a *Application) Run(ctx context.Context) error

Run executes the application using the configured command set.

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

type Command struct {
	*flag.FlagSet
}

Command wraps a FlagSet and provides Fx wiring for CLI subcommands.

func NewCommand added in v2.66.0

func NewCommand(name string) *Command

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 Option

type Option = di.Option

Option is an alias for di.Option.

type RegisterFunc

type RegisterFunc = func(commander Commander)

RegisterFunc registers commands on a Commander.

Jump to

Keyboard shortcuts

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