-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
53 lines (42 loc) · 1.14 KB
/
main.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
package main
import (
"os"
commander "github.com/omegion/cobra-commander"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/omegion/vault-unseal/cmd"
)
const (
// Config file name where a config file will be created.
// For example, $HOME/.vault-unseal/config.yaml.
configFileName = "vault-unseal"
// The environment variable prefix of all environment variables bound to our command line flags.
// For example, --address is bound to VUNSEAL_ADDRESS.
configEnvPrefix = "VUNSEAL"
)
func main() {
root := &cobra.Command{
Use: "vault-unseal",
Short: "Vault Auto Unseal",
Long: "CLI command to automatically unseal Vault",
SilenceUsage: true,
}
cmdr := commander.NewCommander(root).
SetCommand(
cmd.Version(),
cmd.Unseal(),
)
cmdr.SetConfig(getConfig(cmdr.Root.Flags())).Init()
if err := cmdr.Execute(); err != nil {
os.Exit(1)
}
}
func getConfig(flags *pflag.FlagSet) *commander.Config {
configName := configFileName
environmentPrefix := configEnvPrefix
return &commander.Config{
Name: &configName,
EnvironmentPrefix: &environmentPrefix,
Flags: flags,
}
}