Indent snapshot summary details; add Finished message; fix 'to process'
- New ui.Detail method for indented continuation lines under a preceding Complete (visually same as Progress: " 》" in white). - Snapshot summary lines (Files/Data/Storage/Upload/Duration) are now Detail lines indented under "Created snapshot X.". - Local index database prune complete result lines (incomplete snapshots, orphaned files/chunks/blobs) are also Detail lines under a clean Complete header. - "Files: ... to process" → "Files: ... processed" (they have been processed by the time we emit the summary). - "Data: ... (... to process)" → "Data: ... (... processed)". - ui.Writer now tracks warning and error counts emitted; Vaultik prints "Finished successfully." or "Finished (with N warnings)." as the final line of CreateSnapshot.
This commit is contained in:
@@ -407,6 +407,7 @@ Message classes:
|
|||||||
| Warning | `⚠️ Warning:` (orange/yellow) | column 0 | Recoverable problem |
|
| Warning | `⚠️ Warning:` (orange/yellow) | column 0 | Recoverable problem |
|
||||||
| Error | `🛑 ERROR:` (red) | column 0 | Operation aborted |
|
| Error | `🛑 ERROR:` (red) | column 0 | Operation aborted |
|
||||||
| Progress | ` 》` (white) | column 2 | Heartbeat or per-item status during a long-running operation |
|
| Progress | ` 》` (white) | column 2 | Heartbeat or per-item status during a long-running operation |
|
||||||
|
| Detail | ` 》` (white) | column 2 | Continuation/sub-line of a preceding Complete (visually identical to Progress) |
|
||||||
|
|
||||||
Conventions:
|
Conventions:
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,14 @@ const (
|
|||||||
const Marker = "》"
|
const Marker = "》"
|
||||||
|
|
||||||
// Writer formats and emits user-facing messages with optional ANSI color.
|
// Writer formats and emits user-facing messages with optional ANSI color.
|
||||||
|
// It also counts warnings and errors emitted so the caller can summarize at
|
||||||
|
// the end of an operation ("Finished successfully." vs "Finished with
|
||||||
|
// warnings.").
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
out io.Writer
|
out io.Writer
|
||||||
color bool
|
color bool
|
||||||
|
warnings int
|
||||||
|
errors int
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Writer that emits to out. Color is enabled when out is a
|
// New returns a Writer that emits to out. Color is enabled when out is a
|
||||||
@@ -115,6 +120,7 @@ func (w *Writer) Notice(format string, args ...any) {
|
|||||||
|
|
||||||
// Warning prints "⚠️ Warning: " in orange/yellow followed by the message.
|
// Warning prints "⚠️ Warning: " in orange/yellow followed by the message.
|
||||||
func (w *Writer) Warning(format string, args ...any) {
|
func (w *Writer) Warning(format string, args ...any) {
|
||||||
|
w.warnings++
|
||||||
prefix := "⚠️ " + w.paint(ansiYellow+ansiBold, "Warning: ")
|
prefix := "⚠️ " + w.paint(ansiYellow+ansiBold, "Warning: ")
|
||||||
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
|
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
@@ -123,10 +129,25 @@ func (w *Writer) Warning(format string, args ...any) {
|
|||||||
// same writer as everything else; callers that want stderr should
|
// same writer as everything else; callers that want stderr should
|
||||||
// construct a separate Writer for it.
|
// construct a separate Writer for it.
|
||||||
func (w *Writer) Error(format string, args ...any) {
|
func (w *Writer) Error(format string, args ...any) {
|
||||||
|
w.errors++
|
||||||
prefix := "🛑 " + w.paint(ansiRed+ansiBold, "ERROR: ")
|
prefix := "🛑 " + w.paint(ansiRed+ansiBold, "ERROR: ")
|
||||||
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
|
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detail prints an indented continuation line under a preceding Complete
|
||||||
|
// (or other top-level message). Marker " 》" (white) at column 2.
|
||||||
|
// Distinct from Progress (semantically a "heartbeat") in usage but
|
||||||
|
// visually identical.
|
||||||
|
func (w *Writer) Detail(format string, args ...any) {
|
||||||
|
w.emit(ansiWhite, " "+Marker, "", format, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WarningCount returns the number of Warning() calls this writer has emitted.
|
||||||
|
func (w *Writer) WarningCount() int { return w.warnings }
|
||||||
|
|
||||||
|
// ErrorCount returns the number of Error() calls this writer has emitted.
|
||||||
|
func (w *Writer) ErrorCount() int { return w.errors }
|
||||||
|
|
||||||
// Progress prints an indented heartbeat / per-item update, marker in white.
|
// Progress prints an indented heartbeat / per-item update, marker in white.
|
||||||
func (w *Writer) Progress(format string, args ...any) {
|
func (w *Writer) Progress(format string, args ...any) {
|
||||||
w.emit(ansiWhite, " "+Marker, "", format, args)
|
w.emit(ansiWhite, " "+Marker, "", format, args)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ func TestMessageMethodsPlain(t *testing.T) {
|
|||||||
{"Warning", func(w *Writer) { w.Warning("oops") }, "⚠️ Warning: oops\n"},
|
{"Warning", func(w *Writer) { w.Warning("oops") }, "⚠️ Warning: oops\n"},
|
||||||
{"Error", func(w *Writer) { w.Error("boom") }, "🛑 ERROR: boom\n"},
|
{"Error", func(w *Writer) { w.Error("boom") }, "🛑 ERROR: boom\n"},
|
||||||
{"Progress", func(w *Writer) { w.Progress("p") }, " 》 p\n"},
|
{"Progress", func(w *Writer) { w.Progress("p") }, " 》 p\n"},
|
||||||
|
{"Detail", func(w *Writer) { w.Detail("d") }, " 》 d\n"},
|
||||||
{"Banner", func(w *Writer) { w.Banner("hello") }, "hello\n"},
|
{"Banner", func(w *Writer) { w.Banner("hello") }, "hello\n"},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +40,23 @@ func TestMessageMethodsPlain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWarningErrorCounters(t *testing.T) {
|
||||||
|
w, _ := newTestWriter(false)
|
||||||
|
if w.WarningCount() != 0 || w.ErrorCount() != 0 {
|
||||||
|
t.Fatalf("expected fresh writer to have zero counts")
|
||||||
|
}
|
||||||
|
w.Info("normal")
|
||||||
|
w.Warning("first warn")
|
||||||
|
w.Warning("second warn")
|
||||||
|
w.Error("only error")
|
||||||
|
if got, want := w.WarningCount(), 2; got != want {
|
||||||
|
t.Errorf("WarningCount: got %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
if got, want := w.ErrorCount(), 1; got != want {
|
||||||
|
t.Errorf("ErrorCount: got %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestColorOutputContainsANSI(t *testing.T) {
|
func TestColorOutputContainsANSI(t *testing.T) {
|
||||||
w, buf := newTestWriter(true)
|
w, buf := newTestWriter(true)
|
||||||
w.Error("boom")
|
w.Error("boom")
|
||||||
|
|||||||
@@ -92,6 +92,12 @@ func (v *Vaultik) CreateSnapshot(opts *SnapshotCreateOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.UI.WarningCount() > 0 {
|
||||||
|
v.UI.Complete("Finished (with %d warnings).", v.UI.WarningCount())
|
||||||
|
} else {
|
||||||
|
v.UI.Complete("Finished successfully.")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,35 +342,35 @@ func (v *Vaultik) printSnapshotSummary(snapshotID string, startTime time.Time, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
v.UI.Complete("Created snapshot %s.", v.UI.Snapshot(snapshotID))
|
v.UI.Complete("Created snapshot %s.", v.UI.Snapshot(snapshotID))
|
||||||
filesMsg := fmt.Sprintf("Files: %s examined, %s to process, %s unchanged",
|
filesMsg := fmt.Sprintf("Files: %s examined, %s processed, %s unchanged",
|
||||||
v.UI.Count(stats.totalFiles),
|
v.UI.Count(stats.totalFiles),
|
||||||
v.UI.Count(totalFilesChanged),
|
v.UI.Count(totalFilesChanged),
|
||||||
v.UI.Count(stats.totalFilesSkipped))
|
v.UI.Count(stats.totalFilesSkipped))
|
||||||
if stats.totalFilesDeleted > 0 {
|
if stats.totalFilesDeleted > 0 {
|
||||||
filesMsg += fmt.Sprintf(", %s deleted", v.UI.Count(stats.totalFilesDeleted))
|
filesMsg += fmt.Sprintf(", %s deleted", v.UI.Count(stats.totalFilesDeleted))
|
||||||
}
|
}
|
||||||
v.UI.Info("%s.", filesMsg)
|
v.UI.Detail("%s.", filesMsg)
|
||||||
|
|
||||||
dataMsg := fmt.Sprintf("Data: %s total (%s to process)",
|
dataMsg := fmt.Sprintf("Data: %s total (%s processed)",
|
||||||
v.UI.Size(totalBytesAll),
|
v.UI.Size(totalBytesAll),
|
||||||
v.UI.Size(stats.totalBytes))
|
v.UI.Size(stats.totalBytes))
|
||||||
if stats.totalBytesDeleted > 0 {
|
if stats.totalBytesDeleted > 0 {
|
||||||
dataMsg += fmt.Sprintf(", %s deleted", v.UI.Size(stats.totalBytesDeleted))
|
dataMsg += fmt.Sprintf(", %s deleted", v.UI.Size(stats.totalBytesDeleted))
|
||||||
}
|
}
|
||||||
v.UI.Info("%s.", dataMsg)
|
v.UI.Detail("%s.", dataMsg)
|
||||||
|
|
||||||
if stats.totalBlobsUploaded > 0 {
|
if stats.totalBlobsUploaded > 0 {
|
||||||
v.UI.Info("Storage: %s compressed from %s (%.2fx ratio).",
|
v.UI.Detail("Storage: %s compressed from %s (%.2fx ratio).",
|
||||||
v.UI.Size(totalBlobSizeCompressed),
|
v.UI.Size(totalBlobSizeCompressed),
|
||||||
v.UI.Size(totalBlobSizeUncompressed),
|
v.UI.Size(totalBlobSizeUncompressed),
|
||||||
compressionRatio)
|
compressionRatio)
|
||||||
v.UI.Info("Upload: %d blobs, %s in %s (%s).",
|
v.UI.Detail("Upload: %d blobs, %s in %s (%s).",
|
||||||
stats.totalBlobsUploaded,
|
stats.totalBlobsUploaded,
|
||||||
v.UI.Size(stats.totalBytesUploaded),
|
v.UI.Size(stats.totalBytesUploaded),
|
||||||
v.UI.Duration(stats.uploadDuration),
|
v.UI.Duration(stats.uploadDuration),
|
||||||
formatUploadSpeed(stats.totalBytesUploaded, stats.uploadDuration))
|
formatUploadSpeed(stats.totalBytesUploaded, stats.uploadDuration))
|
||||||
}
|
}
|
||||||
v.UI.Info("Snapshot create duration: %s.", v.UI.Duration(snapshotDuration))
|
v.UI.Detail("Snapshot create duration: %s.", v.UI.Duration(snapshotDuration))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSnapshotBlobSizes returns total compressed and uncompressed blob sizes for a snapshot
|
// getSnapshotBlobSizes returns total compressed and uncompressed blob sizes for a snapshot
|
||||||
@@ -1333,11 +1339,11 @@ func (v *Vaultik) PruneDatabase() (*PruneResult, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
snapshotCountAfter := snapshotCountBefore - result.SnapshotsDeleted
|
snapshotCountAfter := snapshotCountBefore - result.SnapshotsDeleted
|
||||||
v.UI.Complete("Pruned local index database: %d incomplete snapshots removed (%d remain), %d orphaned files removed (%d remain), %d orphaned chunks removed (%d remain), %d orphaned blobs removed (%d remain).",
|
v.UI.Complete("Pruned local index database.")
|
||||||
result.SnapshotsDeleted, snapshotCountAfter,
|
v.UI.Detail("Incomplete snapshots: %d removed (%d remain).", result.SnapshotsDeleted, snapshotCountAfter)
|
||||||
result.FilesDeleted, fileCountAfter,
|
v.UI.Detail("Orphaned files: %d removed (%d remain).", result.FilesDeleted, fileCountAfter)
|
||||||
result.ChunksDeleted, chunkCountAfter,
|
v.UI.Detail("Orphaned chunks: %d removed (%d remain).", result.ChunksDeleted, chunkCountAfter)
|
||||||
result.BlobsDeleted, blobCountAfter)
|
v.UI.Detail("Orphaned blobs: %d removed (%d remain).", result.BlobsDeleted, blobCountAfter)
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user