Documentation
¶
Overview ¶
Package cli provides a minimal framework for building command-line applications with named subcommands.
The CLI type is generic over an App parameter, which allows passing application-level dependencies (e.g. database connections, configuration) through to command handlers without global state.
CLIs can be nested by using CLI.Command to convert a child CLI into a Command that can be registered on a parent.
Index ¶
Constants ¶
const ( ExitCodeSuccess = 0 ExitCodeError = 1 ExitCodeUsage = 2 )
Exit codes returned by CLI.Run.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CLI ¶
CLI is a command-line application with a set of named subcommands. The App type parameter represents application-level dependencies shared across commands.
func (*CLI[App]) Command ¶
Command wraps this CLI as a Command with the given description, allowing it to be registered as a subcommand of a parent CLI. This enables nested command hierarchies.
func (*CLI[App]) Run ¶
Run parses the first element of args as a command name and dispatches to the matching Command. It returns an exit code suitable for use with os.Exit. If no command is given or the command is "help", it prints usage information and returns ExitCodeUsage.
type Command ¶
type Command[App any] struct { Description string Run func(ctx context.Context, app App, args []string) error }
Command is a named subcommand with a description and a run function. The description is displayed in help output. The run function receives the context, the application value, and any remaining arguments after the command name.