config unset; config set tweaks (#188)

This commit is contained in:
Michael Quigley 2023-01-30 13:57:48 -05:00
parent 4deec984ac
commit 2e635ba37d
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 64 additions and 0 deletions

View File

@ -58,5 +58,7 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
if zrd.Env != nil && configName == "apiEndpoint" { if zrd.Env != nil && configName == "apiEndpoint" {
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable")) fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
} }
} else {
fmt.Println("zrok configuration not changed")
} }
} }

62
cmd/zrok/configUnset.go Normal file
View File

@ -0,0 +1,62 @@
package main
import (
"fmt"
"github.com/openziti/zrok/tui"
"github.com/openziti/zrok/zrokdir"
"github.com/spf13/cobra"
"os"
)
func init() {
configCmd.AddCommand(newConfigUnsetCommand().cmd)
}
type configUnsetCommand struct {
cmd *cobra.Command
}
func newConfigUnsetCommand() *configUnsetCommand {
cmd := &cobra.Command{
Use: "unset <configName>",
Short: "Unset a value from the environment config",
Args: cobra.ExactArgs(1),
}
command := &configUnsetCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *configUnsetCommand) run(_ *cobra.Command, args []string) {
configName := args[0]
zrd, err := zrokdir.Load()
if err != nil {
panic(err)
}
modified := false
switch configName {
case "apiEndpoint":
if zrd.Cfg != nil && zrd.Cfg.ApiEndpoint != "" {
zrd.Cfg.ApiEndpoint = ""
modified = true
}
default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)
}
if modified {
if err := zrd.Save(); err != nil {
panic(err)
}
fmt.Println("zrok configuration updated")
if zrd.Env != nil && configName == "apiEndpoint" {
fmt.Printf("\n[%v]: because you have a %v-d environment, you won't see your config change until you run %v first!\n\n", tui.WarningLabel, tui.Code.Render("zrok enable"), tui.Code.Render("zrok disable"))
}
} else {
fmt.Println("zrok configuration not changed")
}
}