diff --git a/cmd/zrok/configGet.go b/cmd/zrok/configGet.go index 45480da4..0d1905d0 100644 --- a/cmd/zrok/configGet.go +++ b/cmd/zrok/configGet.go @@ -40,6 +40,12 @@ func (cmd *configGetCommand) run(_ *cobra.Command, args []string) { } else { fmt.Println("apiEndpoint = ") } + case "defaultFrontend": + if env.Config() != nil && env.Config().DefaultFrontend != "" { + fmt.Printf("defaultFrontend = %v\n", env.Config().DefaultFrontend) + } else { + fmt.Println("defaultFrontend = ") + } default: fmt.Printf("unknown config name '%v'\n", configName) } diff --git a/cmd/zrok/configSet.go b/cmd/zrok/configSet.go index 553102e9..44773fbf 100644 --- a/cmd/zrok/configSet.go +++ b/cmd/zrok/configSet.go @@ -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) diff --git a/cmd/zrok/status.go b/cmd/zrok/status.go index fe6d00be..f54f83cb 100644 --- a/cmd/zrok/status.go +++ b/cmd/zrok/status.go @@ -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") diff --git a/environment/env_v0_4/root.go b/environment/env_v0_4/root.go index 28804bac..f085f3f6 100644 --- a/environment/env_v0_4/root.go +++ b/environment/env_v0_4/root.go @@ -223,13 +223,14 @@ func loadConfig() (*env_core.Config, error) { return nil, errors.Wrapf(err, "error unmarshaling config file '%v'", cf) } out := &env_core.Config{ - ApiEndpoint: cfg.ApiEndpoint, + 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") @@ -323,7 +324,8 @@ type metadata struct { } type config struct { - ApiEndpoint string `json:"api_endpoint"` + ApiEndpoint string `json:"api_endpoint"` + DefaultFrontend string `json:"default_frontend"` } type environment struct {