-
Notifications
You must be signed in to change notification settings - Fork 3
/
secret_delete.go
56 lines (46 loc) · 1.18 KB
/
secret_delete.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
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"flag"
"fmt"
"github.com/hexops/cmder"
"github.com/hexops/wrench/internal/errors"
"github.com/hexops/wrench/internal/wrench"
"github.com/hexops/wrench/internal/wrench/api"
)
func init() {
const usage = `
Examples:
Delete a secrets:
$ wrench secret delete [id]
`
// Parse flags for our subcommand.
flagSet := flag.NewFlagSet("delete", flag.ExitOnError)
// Handles calls to our subcommand.
handler := func(args []string) error {
_ = flagSet.Parse(args)
if len(args) != 1 {
return &cmder.UsageError{Err: errors.New("expected [id] argument")}
}
ctx := context.Background()
client, err := wrench.Client(*secretConfigFile)
if err != nil {
return errors.Wrap(err, "Client")
}
_, err = client.SecretsDelete(ctx, &api.SecretsDeleteRequest{ID: args[0]})
if err != nil {
return errors.Wrap(err, "SecretsDelete")
}
return nil
}
// Register the command.
secretCommands = append(secretCommands, &cmder.Command{
FlagSet: flagSet,
Handler: handler,
UsageFunc: func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'wrench secret %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Printf("%s", usage)
},
})
}