Exit 1 when a deletion prompt is not confirmed (closes #423)
check / check (push) Successful in 9m27s

`prune`, `snapshot purge`, `snapshot remove` and `database delete`
printed "Cancelled" or "Aborted." and exited 0 when the prompt was
answered no or stdin ended. They now return vaultik.ErrNotConfirmed,
so the command reports "deletion not confirmed" and exits 1.

`database delete` reads its answer from the command's stdin instead of
os.Stdin, so a test can supply it.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-11 01:19:06 +00:00
1 parent aae7fa17ae
commit 71a232d0f7
9 files changed
+94 -19

No files matched your search

+6
View File
@@ -5,6 +5,7 @@ package vaultik
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
@@ -184,6 +185,11 @@ func (v *Vaultik) printlnStdout(args ...any) {
_, _ = fmt.Fprintln(v.Stdout, args...)
}
// ErrNotConfirmed is returned when the operator answers a confirmation
// prompt with anything but yes, or stdin ends before an answer. Nothing
// the prompt asked about is deleted, and the command exits non-zero.
var ErrNotConfirmed = errors.New("deletion not confirmed")
// scanStdin reads a line of input from stdin.
func (v *Vaultik) scanStdin(a ...any) (int, error) {
return fmt.Fscanln(v.Stdin, a...)