app

package module
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 8 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Documentation

Overview

Package app is the urfave/cli/v3 framework shared by gomatic CLIs. It supplies the generic, command-agnostic glue — the runner/action combinators, the logger-in-metadata convention, the standard global flags, and the run harness — and nothing tied to any one command. Command-specific flags, errors, and trees stay in their own repositories.

Index

Constants

View Source
const LoggerMetadataKey = "logger"

LoggerMetadataKey is the cli.Command metadata key under which the configured logger is stored for retrieval by command actions.

Variables

This section is empty.

Functions

func Default

func Default[C, R any](cfg *C, runner Runner[C, R]) func(context.Context, *cli.Command) error

Default binds a config pointer and runner into a cli action function.

func GetLogger

func GetLogger(c *cli.Command) *slog.Logger

GetLogger returns the logger stored in the root command metadata, or slog.Default when absent or the command is nil.

func Interactive added in v0.6.0

func Interactive[C, R any](cfg *C, runner Runner[C, R]) func(context.Context, *cli.Command) error

Interactive binds a config pointer and runner into a cli action function for a command that owns its output — an interactive REPL, say — and so has no result for the app tier to render. The runner's result is intentionally discarded; only its error propagates. Use Default whenever the command produces a result to encode; result rendering is the common case, not a requirement.

func LoggerBefore

func LoggerBefore(getLogger GetLoggerFunc) func(context.Context, *cli.Command) (context.Context, error)

LoggerBefore returns a cli Before hook that stores the logger built by getLogger in the root command metadata, where GetLogger then finds it.

func OutputFlag

func OutputFlag(envPrefix EnvPrefix) cli.Flag

OutputFlag returns the standard --output/-o global flag selecting the result encoding, sourced from <envPrefix>OUTPUT and defaulting to json. The action combinator reads it to encode each command's result.

func Run

func Run(ctx context.Context, cmd *cli.Command, args []string, exit func(int))

Run executes cmd with signal-aware cancellation (SIGINT/SIGTERM), logging a non-nil error under the command's name and exiting non-zero via exit. The args and exit function are injected so a main can be exercised in tests.

Types

type EnvPrefix

type EnvPrefix string

EnvPrefix is the namespace prepended to each standard flag's environment variable source (e.g. "APP_" yields APP_LOG_LEVEL, APP_LOG_FORMAT, APP_OUTPUT).

type GetLoggerFunc

type GetLoggerFunc func(*cli.Command) *slog.Logger

GetLoggerFunc retrieves a logger for a command; injected so mains and tests can substitute one.

type LoggerFlags

type LoggerFlags struct {
	// Config receives the parsed flag values; it must be non-nil.
	Config *log.LoggerConfig
	// EnvPrefix namespaces the flags' environment variable sources.
	EnvPrefix EnvPrefix
}

LoggerFlags binds the standard logging flags to a shared logger configuration. The config pointer is carried as a field (the binder pattern) so the flag constructors take no pointer parameters; each flag's Destination still writes through to Config as the command line is parsed.

func (LoggerFlags) FormatFlag

func (f LoggerFlags) FormatFlag(def log.Format) cli.Flag

FormatFlag returns the standard --log-format global flag, sourced from <EnvPrefix>LOG_FORMAT, bound to Config, defaulting to def (consumers differ: a CLI defaults to text, a daemon to json).

func (LoggerFlags) LevelFlag

func (f LoggerFlags) LevelFlag() cli.Flag

LevelFlag returns the standard --log-level global flag, sourced from <EnvPrefix>LOG_LEVEL and bound to Config.

type Runner

type Runner[CONFIG any, RESULT any] func(context.Context, *slog.Logger, CONFIG, ...string) (RESULT, error)

Runner executes a command's work: it receives the bound config and positional arguments and returns a result to be encoded. Implementations live in the orchestration (domain) packages of each consumer.

Directories

Path Synopsis
flags
pg
Package pg supplies the standard libpq PG* flag set and the connection Config it binds.
Package pg supplies the standard libpq PG* flag set and the connection Config it binds.

Jump to

Keyboard shortcuts

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