Route direct-stdout command output through internal/ui (closes #149)
version, info, remote info, config, and database delete wrote plain text straight to stdout, so they were unstyled and ignored --quiet. Output is now governed by internal/ui in two buckets. Status lines and confirmations (config init, config set, the database delete prompt) go through the ui message methods and are silenced by --quiet. The data a command exists to produce is written plain -- the version/info/remote-info reports, the snapshot list table, config get values, and the --json documents -- and is never suppressed, since a script depends on it and a marker would corrupt a table or document. The database delete confirmation prompt is always shown. Pure-cli commands reach ui through a small commandUI helper. Model: opus-4-8
This commit was merged in pull request #201.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/spf13/cobra"
|
||||
"sneak.berlin/go/vaultik/internal/ui"
|
||||
)
|
||||
|
||||
// errConfigNotFound is wrapped by all config-resolution failures.
|
||||
@@ -81,6 +82,20 @@ func GetRootFlags() RootFlags {
|
||||
return rootFlags
|
||||
}
|
||||
|
||||
// commandUI returns a UI writer for a command's stdout, in quiet mode
|
||||
// when the global --quiet flag is set. This is how the pure-cli
|
||||
// commands (version, config, database) reach internal/ui: color follows
|
||||
// the writer (a TTY gets color, a captured test buffer does not), and
|
||||
// --quiet silences the same message classes it silences everywhere else.
|
||||
func commandUI(cmd *cobra.Command) *ui.Writer {
|
||||
w := ui.New(cmd.OutOrStdout())
|
||||
if GetRootFlags().Quiet {
|
||||
w.SetQuiet(true)
|
||||
}
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
// ResolveConfigPath resolves the config file path from flags, environment, or default.
|
||||
// Search order: --config flag, VAULTIK_CONFIG env, XDG config dir,
|
||||
// /etc/vaultik/config.yml.
|
||||
|
||||
Reference in New Issue
Block a user