-
Notifications
You must be signed in to change notification settings - Fork 20
/
remove.go
39 lines (30 loc) · 920 Bytes
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"errors"
"flag"
"fmt"
)
const removeHelp = `Delete a secret.`
func (cmd *removeCommand) Name() string { return "rm" }
func (cmd *removeCommand) Args() string { return "[OPTIONS] KEY" }
func (cmd *removeCommand) ShortHelp() string { return removeHelp }
func (cmd *removeCommand) LongHelp() string { return removeHelp }
func (cmd *removeCommand) Hidden() bool { return false }
func (cmd *removeCommand) Register(fs *flag.FlagSet) {}
type removeCommand struct{}
func (cmd *removeCommand) Run(ctx context.Context, args []string) error {
if len(args) < 1 {
return errors.New("must pass a key")
}
key := args[0]
if _, ok := s.Secrets[key]; !ok {
return fmt.Errorf("secret for key %s does not exist", key)
}
delete(s.Secrets, key)
if err := writeSecretsFile(file, s); err != nil {
return err
}
fmt.Printf("Deleted secret key %s\n", key)
return nil
}