diff options
Diffstat (limited to 'cmd/eno/cobra_config.go')
| -rw-r--r-- | cmd/eno/cobra_config.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/cmd/eno/cobra_config.go b/cmd/eno/cobra_config.go new file mode 100644 index 0000000..0872b28 --- /dev/null +++ b/cmd/eno/cobra_config.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + "gitlab.com/whiteboardguy/eno/internal/config" +) + +var configCmd = &cobra.Command{ + Use: "config", + Short: "manage eno configuration", +} + +var configSetCmd = &cobra.Command{ + Use: "set <key> <value...>", + Short: "set a config value", + Args: cobra.MinimumNArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + if err := config.HandlerInit(); err != nil { + return err + } + key := strings.ToUpper(args[0]) + if key == "PUBKEY_SERVICES" { + if len(args) < 3 { + return fmt.Errorf("pubkey_services requires name and url template") + } + return config.PubkeyServiceAdd(args[1], strings.Join(args[2:], " ")) + } + return config.Set(key, strings.Join(args[1:], " ")) + }, +} + +var configGetCmd = &cobra.Command{ + Use: "get <key>", + Short: "get a config value", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + val, err := config.Get(args[0]) + if err != nil { + return err + } + cmd.Println(val) + return nil + }, +} + +var configListCmd = &cobra.Command{ + Use: "list", + Short: "list all config values", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + for _, line := range config.List() { + cmd.Println(line) + } + return nil + }, +} + +var configRemoveCmd = &cobra.Command{ + Use: "remove <key> [name]", + Short: "remove a config value or pubkey service", + Args: cobra.MinimumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + if strings.ToUpper(args[0]) == "PUBKEY_SERVICES" && len(args) >= 2 { + return config.PubkeyServiceRemove(args[1]) + } + return config.Remove(args[0]) + }, +} |