better 'zrok config unset' supporting defaultFrontend; also properly extensible (#663)

This commit is contained in:
Michael Quigley 2024-06-20 15:05:19 -04:00
parent bb8bb0a377
commit e3dec09284
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -3,7 +3,6 @@ package main
import (
"fmt"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/environment/env_core"
"github.com/openziti/zrok/tui"
"github.com/spf13/cobra"
"os"
@ -36,18 +35,25 @@ func (cmd *configUnsetCommand) run(_ *cobra.Command, args []string) {
panic(err)
}
switch configName {
case "apiEndpoint":
if err := env.SetConfig(&env_core.Config{}); err != nil {
if env.Config() != nil {
cfg := env.Config()
switch configName {
case "apiEndpoint":
cfg.ApiEndpoint = ""
if env.IsEnabled() {
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"))
}
case "defaultFrontend":
cfg.DefaultFrontend = ""
default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)
}
if err := env.SetConfig(cfg); err != nil {
tui.Error("unable to save config", err)
}
fmt.Println("zrok configuration updated")
if env.IsEnabled() {
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"))
}
default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)
}
}