Skip to content

Commit 33f0daf

Browse files
authored
Restore cli default cloud and allow opting into interactive selection (#1991)
Summary: Restore cli default cloud and allow opting into interactive selection We've received feedback from users that is confusing to no longer have a default cloud for the pixie cli. This change restores the previous behavior and picks the alphabetically first option as the default (per [CNCF requirements](https://github.com/cncf/foundation/blob/42bc2197cce2f58b31eae5f5067f0fd04ab73482/website-guidelines.md)). Users can pick from the available clouds through the new `--interactive_cloud_select` flag. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Verified the following scenarios - [x] `px get viziers` uses default cloud - [x] `px get --interactive_cloud_select viziers` lists the available clouds and uses the selected valueq ``` $ ./px --interactive_cloud_select get viziers Pixie CLI ✔ withpixie.ai:443 Failed to authenticate. Please retry `px auth login`. ``` Signed-off-by: Dom Del Nano <[email protected]>
1 parent 33244cd commit 33f0daf

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/pixie_cli/pkg/cmd/root.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ import (
4141

4242
var (
4343
AvailableCloudAddrs = []string{
44+
"getcosmic.ai:443",
4445
"withpixie.ai:443",
4546
}
46-
// cloud addr is a required argument. Use empty string since Viper requires a default value.
47-
defaultCloudAddr = ""
47+
defaultCloudAddr = AvailableCloudAddrs[0]
4848
)
4949

5050
func init() {
@@ -53,6 +53,9 @@ func init() {
5353
RootCmd.PersistentFlags().StringP("cloud_addr", "a", defaultCloudAddr, "The address of Pixie Cloud")
5454
viper.BindPFlag("cloud_addr", RootCmd.PersistentFlags().Lookup("cloud_addr"))
5555

56+
RootCmd.PersistentFlags().Bool("interactive_cloud_select", false, "Whether to interactively select the cloud address.")
57+
viper.BindPFlag("interactive_cloud_select", RootCmd.PersistentFlags().Lookup("interactive_cloud_select"))
58+
5659
RootCmd.PersistentFlags().StringP("dev_cloud_namespace", "m", "", "The namespace of Pixie Cloud, if using a cluster local cloud.")
5760
viper.BindPFlag("dev_cloud_namespace", RootCmd.PersistentFlags().Lookup("dev_cloud_namespace"))
5861

@@ -210,9 +213,10 @@ func getCloudAddrIfRequired(cmd *cobra.Command) string {
210213
if slices.Contains(cmdsCloudAddrNotReqd, cmd) || cmd.Short == "Help about any command" {
211214
return defaultCloudAddr
212215
}
216+
interactiveCloudSelect := viper.GetBool("interactive_cloud_select")
213217

214218
cloudAddr := viper.GetString("cloud_addr")
215-
if cloudAddr == "" {
219+
if interactiveCloudSelect {
216220
if !isatty.IsTerminal(os.Stdin.Fd()) {
217221
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.")
218222
os.Exit(1)

0 commit comments

Comments
 (0)