diff --git a/cmd/set.go b/cmd/set.go index 26a7f8d..4e066cb 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -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") } diff --git a/cmd/shared.go b/cmd/shared.go index ca1fc41..9edc0ad 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -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"