crud for defaultFrontend config (#663)

This commit is contained in:
Michael Quigley 2024-06-20 14:31:26 -04:00
parent 671d1aa944
commit bb8bb0a377
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 29 additions and 5 deletions

View File

@ -40,6 +40,12 @@ func (cmd *configGetCommand) run(_ *cobra.Command, args []string) {
} else {
fmt.Println("apiEndpoint = <unset>")
}
case "defaultFrontend":
if env.Config() != nil && env.Config().DefaultFrontend != "" {
fmt.Printf("defaultFrontend = %v\n", env.Config().DefaultFrontend)
} else {
fmt.Println("defaultFrontend = <unset>")
}
default:
fmt.Printf("unknown config name '%v'\n", configName)
}

View File

@ -63,6 +63,20 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
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":
if env.Config() == nil {
if err := env.SetConfig(&env_core.Config{DefaultFrontend: value}); err != nil {
tui.Error("unable to save config", err)
}
} else {
cfg := env.Config()
cfg.DefaultFrontend = value
if err := env.SetConfig(cfg); err != nil {
tui.Error("unable to save config", err)
}
}
fmt.Println("zrok configuration updated")
default:
fmt.Printf("unknown config name '%v'\n", configName)
os.Exit(1)

View File

@ -48,8 +48,10 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) {
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleColoredDark)
t.AppendHeader(table.Row{"Config", "Value", "Source"})
apiEndpoint, from := env.ApiEndpoint()
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, from})
apiEndpoint, apiEndpointFrom := env.ApiEndpoint()
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, apiEndpointFrom})
defaultFrontend, defaultFrontendFrom := env.DefaultFrontend()
t.AppendRow(table.Row{"defaultFrontend", defaultFrontend, defaultFrontendFrom})
t.Render()
_, _ = fmt.Fprintf(os.Stderr, "\n")

View File

@ -224,12 +224,13 @@ func loadConfig() (*env_core.Config, error) {
}
out := &env_core.Config{
ApiEndpoint: cfg.ApiEndpoint,
DefaultFrontend: cfg.DefaultFrontend,
}
return out, nil
}
func saveConfig(cfg *env_core.Config) error {
in := &config{ApiEndpoint: cfg.ApiEndpoint}
in := &config{ApiEndpoint: cfg.ApiEndpoint, DefaultFrontend: cfg.DefaultFrontend}
data, err := json.MarshalIndent(in, "", " ")
if err != nil {
return errors.Wrap(err, "error marshaling config")
@ -324,6 +325,7 @@ type metadata struct {
type config struct {
ApiEndpoint string `json:"api_endpoint"`
DefaultFrontend string `json:"default_frontend"`
}
type environment struct {