Route direct-stdout command output through internal/ui (closes #149)
check / check (pull_request) Successful in 1m45s

version, info, remote info, config, and database delete wrote plain text
straight to stdout, so they were unstyled and ignored --quiet. Output now
falls in two buckets, both governed by internal/ui.

Status lines and confirmations (config init, config set, database
delete) go through the ui message methods: styled, and --quiet silences
them. The data a command exists to produce is written plain, since a
marker would corrupt a table or a parsed document: the version, info, and
remote info reports, the snapshot list table, config get values, and the
--json documents. --quiet silences the human reports and tables but never
the config get value or the --json documents, which a script depends on.
The database delete confirmation prompt is always shown; it is an
interactive exchange the operator must see.

The pure-cli commands reach internal/ui through a small commandUI helper
that builds a ui.Writer on the command's stdout in quiet mode when
--quiet is set. NewForTesting now supplies a UI writer so the quiet gate
is never nil. The README output-style section states the resulting rule.

Model: opus-4-8
This commit is contained in:
2026-09-22 18:03:45 +00:00
parent dd7a610c23
commit b4a539c8f9
14 changed files with 427 additions and 66 deletions
+14 -5
View File
@@ -2,11 +2,11 @@ package cli
import (
"fmt"
"io"
"runtime"
"github.com/spf13/cobra"
"sneak.berlin/go/vaultik/internal/globals"
"sneak.berlin/go/vaultik/internal/ui"
)
// NewVersionCommand creates the version command
@@ -17,16 +17,25 @@ func NewVersionCommand() *cobra.Command {
Long: `Print version, git commit, and build information for vaultik.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
writeVersion(cmd.OutOrStdout())
writeVersion(commandUI(cmd))
},
}
return cmd
}
// writeVersion prints the version report. It takes a writer rather than
// using os.Stdout directly so the output can be asserted on in tests.
func writeVersion(w io.Writer) {
// writeVersion prints the version report through the UI writer. The
// report is the output this command exists to produce, so it is written
// plain (markers would corrupt the aligned report) via the writer's
// underlying stdout; --quiet silences it like any other non-error
// output.
func writeVersion(out *ui.Writer) {
if out.Quiet() {
return
}
w := out.Out()
_, _ = fmt.Fprintf(w, "vaultik %s\n", globals.Version)
_, _ = fmt.Fprintf(w, " commit: %s\n", globals.Commit)
_, _ = fmt.Fprintf(w, " build date: %s\n", globals.CommitDate)