From c9fcaa7b41fc75d62b4753f6580e75993e1c664d Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Fri, 23 Aug 2024 20:28:41 +0000 Subject: [PATCH] Restore cli default cloud and allow opting into interactive selection Signed-off-by: Dom Del Nano --- src/pixie_cli/pkg/cmd/root.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pixie_cli/pkg/cmd/root.go b/src/pixie_cli/pkg/cmd/root.go index 1dde5bafa53..2320e2229e6 100644 --- a/src/pixie_cli/pkg/cmd/root.go +++ b/src/pixie_cli/pkg/cmd/root.go @@ -41,10 +41,10 @@ import ( var ( AvailableCloudAddrs = []string{ + "getcosmic.ai:443", "withpixie.ai:443", } - // cloud addr is a required argument. Use empty string since Viper requires a default value. - defaultCloudAddr = "" + defaultCloudAddr = AvailableCloudAddrs[0] ) func init() { @@ -53,6 +53,9 @@ func init() { RootCmd.PersistentFlags().StringP("cloud_addr", "a", defaultCloudAddr, "The address of Pixie Cloud") viper.BindPFlag("cloud_addr", RootCmd.PersistentFlags().Lookup("cloud_addr")) + RootCmd.PersistentFlags().Bool("interactive_cloud_select", false, "Whether to interactively select the cloud address.") + viper.BindPFlag("interactive_cloud_select", RootCmd.PersistentFlags().Lookup("interactive_cloud_select")) + RootCmd.PersistentFlags().StringP("dev_cloud_namespace", "m", "", "The namespace of Pixie Cloud, if using a cluster local cloud.") viper.BindPFlag("dev_cloud_namespace", RootCmd.PersistentFlags().Lookup("dev_cloud_namespace")) @@ -210,9 +213,10 @@ func getCloudAddrIfRequired(cmd *cobra.Command) string { if slices.Contains(cmdsCloudAddrNotReqd, cmd) || cmd.Short == "Help about any command" { return defaultCloudAddr } + interactiveCloudSelect := viper.GetBool("interactive_cloud_select") cloudAddr := viper.GetString("cloud_addr") - if cloudAddr == "" { + if interactiveCloudSelect { if !isatty.IsTerminal(os.Stdin.Fd()) { utils.Errorf("No cloud address provided during run within non-interactive shell. Please set the cloud address using the `--cloud_addr` flag or `PX_CLOUD_ADDR` environment variable.") os.Exit(1)