feat(VCS): auto-commit hooked up to all changeful commands

This commit is contained in:
Lewis Wynne 2025-12-18 20:57:54 +00:00
parent 63e2cc55a0
commit 9506a2b657
6 changed files with 112 additions and 14 deletions

View file

@ -26,6 +26,7 @@ import (
"fmt"
"io"
"strings"
"unicode/utf8"
"github.com/dgraph-io/badger/v4"
"github.com/spf13/cobra"
@ -118,7 +119,13 @@ func set(cmd *cobra.Command, args []string) error {
},
}
return store.Transaction(trans)
if err := store.Transaction(trans); err != nil {
return err
}
valSummary := summarizeValue(value)
msg := fmt.Sprintf("set %s: %s", spec.Display(), valSummary)
return autoCommit(store, []string{spec.DB}, msg)
}
func init() {
@ -127,3 +134,14 @@ func init() {
setCmd.Flags().DurationP("ttl", "t", 0, "Expire the key after the provided duration (e.g. 24h, 30m)")
setCmd.Flags().BoolP("interactive", "i", false, "Prompt before overwriting an existing key")
}
func summarizeValue(v []byte) string {
if !utf8.Valid(v) {
return "(binary)"
}
s := string(v)
if len(s) > 80 {
return s[:80] + "..."
}
return s
}