Documentation
¶
Overview ¶
Package clix provides CLI convenience functions for Frostyard tools, wrapping charmbracelet/fang and spf13/cobra with standardized version injection, common flags, JSON output helpers, and reporter factory.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( JSONOutput bool // --json flag value Verbose bool // --verbose / -v flag value DryRun bool // --dry-run / -n flag value Silent bool // --silent / -s flag value )
Common flag values, populated when Run() registers persistent flags.
var Stderr io.Writer
Stderr, when non-nil, replaces the process's standard error for the text reporter returned by NewReporter. Same contract as Stdout: nil means "use the current os.Stderr at call time".
var Stdout io.Writer
Stdout, when non-nil, replaces the process's standard output for every clix output path (OutputJSON, OutputJSONError, and the JSON reporter from NewReporter). It exists so tests — in clix and in consuming CLIs — can capture output with a bytes.Buffer instead of swapping os.Stdout. It defaults to nil, which means "use the current os.Stdout at call time", so consumers that already swap os.Stdout keep working unchanged.
Functions ¶
func BindViper ¶
BindViper binds the common flags (--json, --verbose, --dry-run, --silent) to viper. Call this in a PersistentPreRunE if your app uses viper for config management.
func NewReporter ¶
NewReporter returns the appropriate reporter based on the Silent and JSONOutput flags. Silent mode: NoopReporter (suppresses all output). Silent takes priority over JSON. JSON mode: JSONReporter writing to stdout (for piping/parsing). Text mode: TextReporter writing to stderr (keeps stdout clean for data). The writers are resolved through Stdout / Stderr when set, otherwise the current os.Stdout / os.Stderr.
func OutputJSON ¶
OutputJSON writes data as indented JSON to stdout if JSONOutput is true. Returns true if output was written, false if JSON mode is not active. If encoding fails, a fallback error envelope is written to stdout and the encoding error is returned alongside true (output was still written). Output goes to Stdout when set, otherwise to os.Stdout.
func OutputJSONError ¶
OutputJSONError writes a structured error object as JSON to stdout and returns a wrapped error for the caller to propagate. If err is nil, the message alone is used as the error text.
Types ¶
type App ¶
App holds build-time metadata for a CLI application. Create one in main() and call Run() to execute the root command.
func (*App) Run ¶
Run registers common persistent flags on cmd, then executes the command via fang.Execute with the formatted version string and signal handling.
func (*App) VersionString ¶
VersionString returns a formatted version string including commit, date, and builder info. Example: "1.2.3 (Commit: abc) (Date: 2026-01-01) (Built by: ci)"
Directories
¶
| Path | Synopsis |
|---|---|
|
tests
|
|
|
e2e/exampletool
command
Command exampletool is the consumer program clix's end-to-end suite builds and runs as a subprocess.
|
Command exampletool is the consumer program clix's end-to-end suite builds and runs as a subprocess. |