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 ¶
- Variables
- func Errorf(format string, args ...any)
- func Printf(format string, args ...any)
- func Println(args ...any)
- func QuietOnlyf(format string, args ...any)
- func Quietf(format string, args ...any)
- func SetLevelFromFlags(silent, quiet, verbose bool)
- func Sprintf(format string, args ...any) string
- func Verbosef(format string, args ...any)
- func Writer() io.Writer
- type Flags
- type Verbosity
Constants ¶
This section is empty.
Variables ¶
var Err io.Writer = os.Stderr
Err is where Errorf writes, stderr, apart from Out so errors stay visible when Out is redirected.
var Level = VerbosityNormal
Level is the verbosity, set once from the flags before any output.
var Out io.Writer = os.Stdout
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 Println ¶
func Println(args ...any)
Println prints normal output and a newline, nothing in quiet or silent modes.
func QuietOnlyf ¶
QuietOnlyf prints only in quiet mode, for a line normal mode prints another way.
func Quietf ¶
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 ¶
Sprintf formats and renders colour tags, for a coloured fragment to pass on or print elsewhere.
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.
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
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.