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:
@@ -0,0 +1,41 @@
|
||||
package vaultik_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"sneak.berlin/go/vaultik/internal/log"
|
||||
)
|
||||
|
||||
// TestListSnapshots_QuietSuppressesTableNotJSON is the --quiet contract
|
||||
// for `snapshot list`: the human table is silenced, but the --json
|
||||
// document a script depends on still emits. A local snapshot with its
|
||||
// remote counterpart present is used so there are no drift notes, whose
|
||||
// warnings would emit even under --quiet.
|
||||
func TestListSnapshots_QuietSuppressesTableNotJSON(t *testing.T) {
|
||||
log.Initialize(log.Config{})
|
||||
t.Parallel()
|
||||
|
||||
env := newListEnv(t)
|
||||
|
||||
ts := time.Date(2026, 3, 1, 10, 0, 0, 0, time.UTC)
|
||||
env.addLocal(t, listLocalID, ts)
|
||||
env.addRemote(t, listLocalID, ts)
|
||||
|
||||
env.v.UI.SetQuiet(true)
|
||||
|
||||
// Table mode: nothing on stdout.
|
||||
require.NoError(t, env.v.ListSnapshots(false))
|
||||
require.Empty(t, env.stdout.String(),
|
||||
"the table must be suppressed under --quiet")
|
||||
|
||||
// JSON mode: the document is still written despite the quiet UI.
|
||||
env.stdout.Reset()
|
||||
require.NoError(t, env.v.ListSnapshots(true))
|
||||
|
||||
rows := decodeListJSON(t, env.stdout.String())
|
||||
require.Len(t, rows, 1)
|
||||
require.Equal(t, listLocalID, rows[0].ID,
|
||||
"the --json document must still emit under --quiet")
|
||||
}
|
||||
Reference in New Issue
Block a user