-
Notifications
You must be signed in to change notification settings - Fork 20
/
create.go
45 lines (36 loc) · 1.11 KB
/
create.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
40
41
42
43
44
45
package main
import (
"context"
"errors"
"flag"
"fmt"
)
const createHelp = `Create a secret.`
func (cmd *createCommand) Name() string { return "create" }
func (cmd *createCommand) Args() string { return "[OPTIONS] KEY VALUE" }
func (cmd *createCommand) ShortHelp() string { return createHelp }
func (cmd *createCommand) LongHelp() string { return createHelp }
func (cmd *createCommand) Hidden() bool { return false }
func (cmd *createCommand) Register(fs *flag.FlagSet) {
fs.BoolVar(&cmd.force, "force", false, "force overwrite existing value")
fs.BoolVar(&cmd.force, "f", false, "force overwrite existing value")
}
type createCommand struct {
force bool
}
func (cmd *createCommand) Run(ctx context.Context, args []string) error {
if len(args) < 2 {
return errors.New("must pass a key and value")
}
// Check if we are updating.
verb := "Added"
_, isUpdating := s.Secrets[args[0]]
if isUpdating {
verb = "Updated"
}
// Add the key value pair to secrets.
key, value := args[0], args[1]
s.setKeyValue(key, value, cmd.force)
fmt.Printf("%s %s %s to secrets\n", verb, key, value)
return nil
}