Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore cli default cloud and allow opting into interactive selection #1991

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/pixie_cli/pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"))

Expand Down Expand Up @@ -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)
Expand Down
Loading