All user-facing output now goes through a single ui.Writer with a
uniform style:
》 (white) for begin / info / notice
》 (green) for complete / success
Warning: for warnings (orange)
ERROR: for errors (red)
》 (indented) for progress heartbeats
Color is enabled when stdout is a TTY and NO_COLOR is unset.
Standards:
- Complete-sentence messages with fully qualified terms ("backup
destination store", "local index database", "snapshot source
files enumeration").
- Every Complete has a matching Begin.
- Natural verb tense conveys state ("Uploading" -> "Uploaded"). The
words "begin"/"complete" never appear in message bodies; the marker
color carries that information.
- ETA means clock time, not duration. Progress lines say "estimated
remaining time (<dur>), finish at <time>" with both labeled.
Adds globals.CommitDate (populated by Makefile/Dockerfile/goreleaser
via ldflags from `git show -s --format=%cI HEAD`) and a startup banner
printed once per invocation.
Strips fx call-chain noise from startup errors so users see the actual
underlying error (e.g. "creating base path: mkdir /Volumes/BACKUPS:
permission denied" instead of three layers of "could not build
arguments for function ...").
README documents the output style and the ui package conventions.
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package snapshot
|
|
|
|
import (
|
|
"github.com/spf13/afero"
|
|
"go.uber.org/fx"
|
|
"sneak.berlin/go/vaultik/internal/config"
|
|
"sneak.berlin/go/vaultik/internal/database"
|
|
"sneak.berlin/go/vaultik/internal/storage"
|
|
"sneak.berlin/go/vaultik/internal/ui"
|
|
)
|
|
|
|
// ScannerParams holds parameters for scanner creation
|
|
type ScannerParams struct {
|
|
EnableProgress bool
|
|
UI *ui.Writer // Where user-facing scanner messages go; nil = discard
|
|
Fs afero.Fs
|
|
Exclude []string // Exclude patterns (combined global + snapshot-specific)
|
|
SkipErrors bool // Skip file read errors (log loudly but continue)
|
|
}
|
|
|
|
// Module exports backup functionality as an fx module.
|
|
// It provides a ScannerFactory that can create Scanner instances
|
|
// with custom parameters while sharing common dependencies.
|
|
var Module = fx.Module("backup",
|
|
fx.Provide(
|
|
provideScannerFactory,
|
|
NewSnapshotManager,
|
|
),
|
|
)
|
|
|
|
// ScannerFactory creates scanners with custom parameters
|
|
type ScannerFactory func(params ScannerParams) *Scanner
|
|
|
|
func provideScannerFactory(cfg *config.Config, repos *database.Repositories, storer storage.Storer) ScannerFactory {
|
|
return func(params ScannerParams) *Scanner {
|
|
// Use provided excludes, or fall back to global config excludes
|
|
excludes := params.Exclude
|
|
if len(excludes) == 0 {
|
|
excludes = cfg.Exclude
|
|
}
|
|
|
|
return NewScanner(ScannerConfig{
|
|
FS: params.Fs,
|
|
ChunkSize: cfg.ChunkSize.Int64(),
|
|
Repositories: repos,
|
|
Storage: storer,
|
|
MaxBlobSize: cfg.BlobSizeLimit.Int64(),
|
|
CompressionLevel: cfg.CompressionLevel,
|
|
AgeRecipients: cfg.AgeRecipients,
|
|
EnableProgress: params.EnableProgress,
|
|
UI: params.UI,
|
|
Exclude: excludes,
|
|
SkipErrors: params.SkipErrors,
|
|
})
|
|
}
|
|
}
|