Help us shape the future of Go! Take the 2026 Go Developer Survey

flaghelp

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package flaghelp renders flag usage with the conventional CLI spelling: --name for multi-character names and -n for one-character aliases.

It is deliberately a LEAF package: stdlib plus one terminal-width helper, and nothing else. It was extracted from internal/cliconfig because Go's unit of dependency is the package, not the function — importing cliconfig for a flag formatter also linked internal/app and, through it, k8s.io/client-go, the 1Password WASM SDK, Redis, AWS and OpenTelemetry. cmd/mecademo did exactly that for a single PrintDefaults call, which cost 71 MB (84.3 -> 13.0 MB) in a binary that runs a fully offline scripted demo.

Keep it leaf. Anything needing app.Config, provider credentials or MCP profiles belongs in internal/cliconfig, not here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintDefaults

func PrintDefaults(w io.Writer, fs *flag.FlagSet)

PrintDefaults writes every flag using the conventional CLI spelling: --name for multi-character names and -n for one-character aliases.

func PrintDefaultsExcluding

func PrintDefaultsExcluding(w io.Writer, fs *flag.FlagSet, exclude map[string]bool)

PrintDefaultsExcluding writes a flag.FlagSet's defaults, skipping any flag whose name is in exclude. It is the ONE filtered-defaults formatter shared by the cmd mains' progressive help renderers, so there is no second hand-rolled PrintDefaults.

It does NOT mutate, rebind, or copy the source FlagSet: it iterates the real flags via VisitAll and formats each in place, so original flag.Value defaults are untouched. A nil exclude set (or an empty map) renders every flag.

The per-flag formatting follows flag.PrintDefaults for the back-quoted/type name from flag.UnquoteUsage, indentation, embedded-newline rewrite, and default-value annotation. It deliberately displays multi-character names as conventional long options (--name), while one-character names remain short options (-n). Long usage strings are word-wrapped to helpWrapWidth so narrow terminals never receive >80-col lines.

func PrintFlagDefault

func PrintFlagDefault(w io.Writer, f *flag.Flag)

PrintFlagDefault writes a single flag's usage block in the format of flag.PrintDefaults (possibly word-wrapped). It is the selected/predicate form grouped progressive-help renderers use (a grouped renderer sorts + selects flag names, then calls this per flag), keeping ONE formatter implementation behind both the exhaustive and the grouped paths.

Types

This section is empty.

Jump to

Keyboard shortcuts

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