cout

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cout prints for the person running a tool, as clog logs for whoever diagnoses it. Every call carries a least verbosity, so --quiet and --verbose are honoured in one place, and colour tags such as <red>...</> render anywhere in the output and strip on a plain terminal.

Index

Constants

This section is empty.

Variables

Err is where Errorf writes, stderr, apart from Out so errors stay visible when Out is redirected.

Level is the verbosity, set once from the flags before any output.

Out is where normal output goes, stdout unless changed. A tool whose stdout carries its real output, a JSON document or an MCP session, points this at stderr so progress lines stay out of it.

Functions

func Errorf

func Errorf(format string, args ...any)

Errorf prints an error to Err in every mode but silent.

func Printf

func Printf(format string, args ...any)

Printf prints normal output, nothing in quiet or silent modes.

func Println

func Println(args ...any)

Println prints normal output and a newline, nothing in quiet or silent modes.

func QuietOnlyf

func QuietOnlyf(format string, args ...any)

QuietOnlyf prints only in quiet mode, for a line normal mode prints another way.

func Quietf

func Quietf(format string, args ...any)

Quietf prints in quiet mode and above: the one line a script parses, which normal output shows too.

func SetLevelFromFlags added in v0.2.0

func SetLevelFromFlags(silent, quiet, verbose bool)

SetLevelFromFlags sets the package Level from individual flag values; it is the one-liner that replaces the switch every tool used to carry.

func Sprintf

func Sprintf(format string, args ...any) string

Sprintf formats and renders colour tags, for a coloured fragment to pass on or print elsewhere.

func Verbosef

func Verbosef(format string, args ...any)

Verbosef prints detail only asked for with -v.

func Writer

func Writer() io.Writer

Writer is Out at Normal and above and io.Discard below, for output that streams through a tabwriter or an encoder.

Types

type Flags added in v0.2.0

type Flags struct {
	Silent  bool `mapstructure:"silent"`
	JSON    bool `mapstructure:"json"`
	Quiet   bool `mapstructure:"quiet"`
	Verbose bool `mapstructure:"verbose"`
}

Flags is the set of verbosity flags katbyte tools expose. Embed it in a tool's flag struct with `mapstructure:",squash"` and viper fills it from the "silent", "json", "quiet" and "verbose" keys; a tool registers only the flags it offers and keeps ownership of their names, shorthands and help text.

func (Flags) Apply added in v0.2.0

func (f Flags) Apply()

Apply sets the package Level from the flags. Call it once, after the flags are parsed and before any output.

func (Flags) Level added in v0.2.0

func (f Flags) Level() Verbosity

Level returns the verbosity the flags select. Silent wins over JSON, which wins over quiet, which wins over verbose, so contradictory flags err on the side of less output; none set means Normal.

type Verbosity

type Verbosity int

Verbosity is how much a tool prints, ordered so "Normal and above" is a comparison.

const (
	// VerbositySilent prints nothing, not even errors: only the exit code.
	VerbositySilent Verbosity = iota
	// VerbosityJSON keeps stdout for a JSON document the tool writes itself; errors still go to Err.
	VerbosityJSON
	// VerbosityQuiet prints only the lines a script parses (Quietf, QuietOnlyf) and errors.
	VerbosityQuiet
	// VerbosityNormal is the default: everything a person wants to see.
	VerbosityNormal
	// VerbosityVerbose adds the detail behind Verbosef, -v.
	VerbosityVerbose
)

The verbosity levels, from least to most output.

func LevelFromFlags added in v0.2.0

func LevelFromFlags(silent, quiet, verbose bool) Verbosity

LevelFromFlags is Flags.Level for tools that read their flags individually, for example straight from viper in a cobra pre-run hook. Tools with a JSON mode use Flags, which is the only place that level is selected.

func (Verbosity) String

func (v Verbosity) String() string

String is the level's name, as the flag that selects it is spelled.

Jump to

Keyboard shortcuts

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