feat(set): --secret flag to mark input as a secret
This commit is contained in:
parent
5cdcc1d3d3
commit
42735143e7
2 changed files with 15 additions and 1 deletions
12
cmd/set.go
12
cmd/set.go
|
|
@ -50,12 +50,21 @@ func set(cmd *cobra.Command, args []string) error {
|
||||||
value = bytes
|
value = bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secret, err := cmd.Flags().GetBool("secret")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
trans := TransactionArgs{
|
trans := TransactionArgs{
|
||||||
key: args[0],
|
key: args[0],
|
||||||
readonly: false,
|
readonly: false,
|
||||||
sync: false,
|
sync: false,
|
||||||
transact: func(tx *badger.Txn, k []byte) error {
|
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() {
|
func init() {
|
||||||
rootCmd.AddCommand(setCmd)
|
rootCmd.AddCommand(setCmd)
|
||||||
|
setCmd.Flags().Bool("secret", false, "Mark the stored value as a secret")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,10 @@ type errNotFound struct {
|
||||||
suggestions []string
|
suggestions []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
metaSecret byte = 0x1
|
||||||
|
)
|
||||||
|
|
||||||
func (err errNotFound) Error() string {
|
func (err errNotFound) Error() string {
|
||||||
if len(err.suggestions) == 0 {
|
if len(err.suggestions) == 0 {
|
||||||
return "no suggestions found"
|
return "no suggestions found"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue