Print the mnemonic and the vault and unlocker listings to stdout (closes #138)
check / check (push) Waiting to run
check / check (push) Waiting to run
`secret generate mnemonic`, `secret vault list` and `secret unlocker list`, in text and `--json` form, printed through cobra's `cmd.Println` and `cmd.Printf`. Those write to stderr when no output writer is set, and the binary sets none, so a pipe or `$(...)` got nothing. They now write to `cmd.OutOrStdout()`, as `secret list` does, and so does "No versions found" from `secret version list`. Status messages and the warning printed after the mnemonic stay on stderr. A new test runs the built binary and reads the stdout of `generate mnemonic` and of both listings in both forms. Model: opus-5-5
This commit was merged in pull request #164.
This commit is contained in:
@@ -186,6 +186,8 @@ func (cli *Instance) ListVaults(cmd *cobra.Command, jsonOutput bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
out := cmd.OutOrStdout()
|
||||
|
||||
if jsonOutput { //nolint:nestif // Separate JSON and text output formatting logic
|
||||
// Get current vault name for context
|
||||
currentVault := ""
|
||||
@@ -205,13 +207,13 @@ func (cli *Instance) ListVaults(cmd *cobra.Command, jsonOutput bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.Println(string(jsonBytes))
|
||||
_, _ = fmt.Fprintln(out, string(jsonBytes))
|
||||
} else {
|
||||
// Text output
|
||||
cmd.Println("Available vaults:")
|
||||
_, _ = fmt.Fprintln(out, "Available vaults:")
|
||||
|
||||
if len(vaults) == 0 {
|
||||
cmd.Println(" (none)")
|
||||
_, _ = fmt.Fprintln(out, " (none)")
|
||||
} else {
|
||||
// Try to get current vault for marking
|
||||
currentVault := ""
|
||||
@@ -223,9 +225,9 @@ func (cli *Instance) ListVaults(cmd *cobra.Command, jsonOutput bool) error {
|
||||
|
||||
for _, vaultName := range vaults {
|
||||
if vaultName == currentVault {
|
||||
cmd.Printf(" %s (current)\n", vaultName)
|
||||
_, _ = fmt.Fprintf(out, " %s (current)\n", vaultName)
|
||||
} else {
|
||||
cmd.Printf(" %s\n", vaultName)
|
||||
_, _ = fmt.Fprintf(out, " %s\n", vaultName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user