app

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

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.

Documentation

Overview

Package app holds Deps, the dependencies every command receives.

Index

Constants

View Source
const LevelTrace = slog.LevelDebug - 4

LevelTrace is the level enabled by -vvv.

Variables

This section is empty.

Functions

func EnableVirtualTerminal

func EnableVirtualTerminal(io.Writer) bool

EnableVirtualTerminal reports whether w can show ANSI colors. Outside Windows it always can.

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is a terminal.

func NewLogger

func NewLogger(w io.Writer, o LogOptions) *slog.Logger

NewLogger returns a tint text logger or a JSON logger writing to w.

Types

type Deps

type Deps struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	Env   Env
	Clock func() time.Time
	Getwd func() (string, error)
	// HTTPTransport carries every outgoing request; nil means the network. Tests set a cassette.
	HTTPTransport http.RoundTripper

	// Logger is set by the root command before any RunE runs.
	Logger *slog.Logger
	// Config is nil until a command loads it.
	Config *config.Result
}

Deps carries everything a command needs from the outside world.

type Env

type Env []string

Env is an injected environment, in os.Environ "KEY=value" form.

func (Env) Get

func (e Env) Get(key string) string

Get returns the value of key, or "" when unset.

func (Env) Lookup

func (e Env) Lookup(key string) (string, bool)

Lookup returns the value of key and whether it is set.

type LogFormat

type LogFormat string

LogFormat selects the slog handler.

const (
	LogFormatText LogFormat = "text"
	LogFormatJSON LogFormat = "json"
)

Supported log formats.

func ParseLogFormat

func ParseLogFormat(s string) (LogFormat, error)

ParseLogFormat validates a --log-format value.

type LogOptions

type LogOptions struct {
	Format  LogFormat
	Verbose int // number of -v flags
	Quiet   bool
	Color   bool
}

LogOptions configures NewLogger.

func (LogOptions) Level

func (o LogOptions) Level() slog.Level

Level maps -q and the -v count to a slog level. The default is warn.

Jump to

Keyboard shortcuts

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