feat(set): --secret flag to mark input as a secret

This commit is contained in:
Lewis Wynne 2025-11-06 23:54:06 +00:00
parent 5cdcc1d3d3
commit 42735143e7
2 changed files with 15 additions and 1 deletions

View file

@ -50,12 +50,21 @@ func set(cmd *cobra.Command, args []string) error {
value = bytes
}
secret, err := cmd.Flags().GetBool("secret")
if err != nil {
return err
}
trans := TransactionArgs{
key: args[0],
readonly: false,
sync: false,
transact: func(tx *badger.Txn, k []byte) error {
return tx.Set(k, value)
entry := badger.NewEntry(k, value)
if secret {
entry = entry.WithMeta(metaSecret)
}
return tx.SetEntry(entry)
},
}
@ -64,4 +73,5 @@ func set(cmd *cobra.Command, args []string) error {
func init() {
rootCmd.AddCommand(setCmd)
setCmd.Flags().Bool("secret", false, "Mark the stored value as a secret")
}

View file

@ -38,6 +38,10 @@ type errNotFound struct {
suggestions []string
}
const (
metaSecret byte = 0x1
)
func (err errNotFound) Error() string {
if len(err.suggestions) == 0 {
return "no suggestions found"