From a77db5f25649af03f18b86cfd41762c9de1ed23a Mon Sep 17 00:00:00 2001 From: mrrishi Date: Tue, 12 Nov 2024 00:37:58 +0530 Subject: [PATCH] fix validate flags --- cmd/akamai/create.go | 18 ++++++++---------- cmd/aws/create.go | 19 +++++++++---------- cmd/azure/create.go | 10 ++++++---- cmd/civo/create.go | 18 ++++++++---------- cmd/digitalocean/create.go | 20 ++++++++++---------- cmd/google/create.go | 19 +++++++++---------- cmd/vultr/create.go | 19 +++++++++---------- 7 files changed, 59 insertions(+), 64 deletions(-) diff --git a/cmd/akamai/create.go b/cmd/akamai/create.go index 18ca16e2e..0c879ca39 100644 --- a/cmd/akamai/create.go +++ b/cmd/akamai/create.go @@ -39,10 +39,12 @@ func createAkamai(cmd *cobra.Command, _ []string) error { return fmt.Errorf("catalog validation failed: %w", err) } - err = ValidateProvidedFlags(cliFlags.GitProvider) - if err != nil { - progress.Error(err.Error()) - return fmt.Errorf("failed to validate flags: %w", err) + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider) + if err != nil { + progress.Error(err.Error()) + return fmt.Errorf("failed to validate flags: %w", err) + } } utilities.CreateK1ClusterDirectory(clusterNameFlag) @@ -99,9 +101,7 @@ func createAkamai(cmd *cobra.Command, _ []string) error { } func ValidateProvidedFlags(gitProvider string) error { - if progress.CanRunBubbleTea { - progress.AddStep("Validate provided flags") - } + progress.AddStep("Validate provided flags") if os.Getenv("LINODE_TOKEN") == "" { return fmt.Errorf("your LINODE_TOKEN is not set - please set and re-run your last command") @@ -128,9 +128,7 @@ func ValidateProvidedFlags(gitProvider string) error { log.Info().Msgf("%q %s", "gitlab.com", key.Type()) } - if progress.CanRunBubbleTea { - progress.CompleteStep("Validate provided flags") - } + progress.CompleteStep("Validate provided flags") return nil } diff --git a/cmd/aws/create.go b/cmd/aws/create.go index d454d9fc5..b5fa37cfc 100644 --- a/cmd/aws/create.go +++ b/cmd/aws/create.go @@ -41,10 +41,12 @@ func createAws(cmd *cobra.Command, _ []string) error { return fmt.Errorf("invalid catalog apps: %w", err) } - err = ValidateProvidedFlags(cliFlags.GitProvider) - if err != nil { - progress.Error(err.Error()) - return fmt.Errorf("failed to validate provided flags: %w", err) + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider) + if err != nil { + progress.Error(err.Error()) + return fmt.Errorf("failed to validate provided flags: %w", err) + } } utilities.CreateK1ClusterDirectory(cliFlags.ClusterName) @@ -137,9 +139,8 @@ func createAws(cmd *cobra.Command, _ []string) error { } func ValidateProvidedFlags(gitProvider string) error { - if progress.CanRunBubbleTea { - progress.AddStep("Validate provided flags") - } + progress.AddStep("Validate provided flags") + // Validate required environment variables for dns provider if dnsProviderFlag == "cloudflare" { if os.Getenv("CF_API_TOKEN") == "" { @@ -162,9 +163,7 @@ func ValidateProvidedFlags(gitProvider string) error { log.Info().Msgf("%q %s", "gitlab.com", key.Type()) } - if progress.CanRunBubbleTea { - progress.CompleteStep("Validate provided flags") - } + progress.CompleteStep("Validate provided flags") return nil } diff --git a/cmd/azure/create.go b/cmd/azure/create.go index 809fa7777..6fd666bfd 100644 --- a/cmd/azure/create.go +++ b/cmd/azure/create.go @@ -51,10 +51,12 @@ func createAzure(cmd *cobra.Command, _ []string) error { return nil } - err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider, cliFlags.DNSAzureRG) - if err != nil { - progress.Error(err.Error()) - return nil + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider, cliFlags.DNSProvider, cliFlags.DNSAzureRG) + if err != nil { + progress.Error(err.Error()) + return nil + } } // If cluster setup is complete, return diff --git a/cmd/civo/create.go b/cmd/civo/create.go index 7a01d717e..e5c278e8b 100644 --- a/cmd/civo/create.go +++ b/cmd/civo/create.go @@ -39,10 +39,12 @@ func createCivo(cmd *cobra.Command, _ []string) error { return fmt.Errorf("catalog apps validation failed: %w", err) } - err = ValidateProvidedFlags(cliFlags.GitProvider) - if err != nil { - progress.Error(err.Error()) - return fmt.Errorf("failed to validate provided flags: %w", err) + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider) + if err != nil { + progress.Error(err.Error()) + return fmt.Errorf("failed to validate provided flags: %w", err) + } } // If cluster setup is complete, return @@ -102,9 +104,7 @@ func createCivo(cmd *cobra.Command, _ []string) error { } func ValidateProvidedFlags(gitProvider string) error { - if progress.CanRunBubbleTea { - progress.AddStep("Validate provided flags") - } + progress.AddStep("Validate provided flags") if os.Getenv("CIVO_TOKEN") == "" { return fmt.Errorf("your CIVO_TOKEN is not set - please set and re-run your last command") @@ -132,9 +132,7 @@ func ValidateProvidedFlags(gitProvider string) error { log.Info().Msgf("gitlab.com %q", key.Type()) } - if progress.CanRunBubbleTea { - progress.CompleteStep("Validate provided flags") - } + progress.CompleteStep("Validate provided flags") return nil } diff --git a/cmd/digitalocean/create.go b/cmd/digitalocean/create.go index 9bbac465e..85675d038 100644 --- a/cmd/digitalocean/create.go +++ b/cmd/digitalocean/create.go @@ -44,10 +44,12 @@ func createDigitalocean(cmd *cobra.Command, _ []string) error { return errors.New("catalog did not pass a validation check") } - err = ValidateProvidedFlags(cliFlags.GitProvider) - if err != nil { - progress.Error(err.Error()) - return fmt.Errorf("failed to validate provided flags: %w", err) + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider) + if err != nil { + progress.Error(err.Error()) + return fmt.Errorf("failed to validate provided flags: %w", err) + } } // If cluster setup is complete, return @@ -111,9 +113,8 @@ func createDigitalocean(cmd *cobra.Command, _ []string) error { } func ValidateProvidedFlags(gitProvider string) error { - if progress.CanRunBubbleTea { - progress.AddStep("Validate provided flags") - } + progress.AddStep("Validate provided flags") + // Validate required environment variables for dns provider if dnsProviderFlag == "cloudflare" { if os.Getenv("CF_API_TOKEN") == "" { @@ -142,8 +143,7 @@ func ValidateProvidedFlags(gitProvider string) error { log.Info().Msgf("%q %s", "gitlab.com", key.Type()) } - if progress.CanRunBubbleTea { - progress.CompleteStep("Validate provided flags") - } + progress.CompleteStep("Validate provided flags") + return nil } diff --git a/cmd/google/create.go b/cmd/google/create.go index 5aaabc71b..0099cfd66 100644 --- a/cmd/google/create.go +++ b/cmd/google/create.go @@ -40,10 +40,12 @@ func createGoogle(cmd *cobra.Command, _ []string) error { return fmt.Errorf("catalog apps validation failed: %w", err) } - err = ValidateProvidedFlags(cliFlags.GitProvider) - if err != nil { - progress.Error(err.Error()) - return fmt.Errorf("validation of provided flags failed: %w", err) + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider) + if err != nil { + progress.Error(err.Error()) + return fmt.Errorf("validation of provided flags failed: %w", err) + } } clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete") @@ -104,9 +106,7 @@ func createGoogle(cmd *cobra.Command, _ []string) error { } func ValidateProvidedFlags(gitProvider string) error { - if progress.CanRunBubbleTea { - progress.AddStep("Validate provided flags") - } + progress.AddStep("Validate provided flags") if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" { return fmt.Errorf("your GOOGLE_APPLICATION_CREDENTIALS is not set - please set and re-run your last command") @@ -133,8 +133,7 @@ func ValidateProvidedFlags(gitProvider string) error { log.Info().Msgf("%q %s", "gitlab.com", key.Type()) } - if progress.CanRunBubbleTea { - progress.CompleteStep("Validate provided flags") - } + progress.CompleteStep("Validate provided flags") + return nil } diff --git a/cmd/vultr/create.go b/cmd/vultr/create.go index 020e96801..5fc3c8685 100644 --- a/cmd/vultr/create.go +++ b/cmd/vultr/create.go @@ -44,10 +44,12 @@ func createVultr(cmd *cobra.Command, _ []string) error { return errors.New("catalog validation failed") } - err = ValidateProvidedFlags(cliFlags.GitProvider) - if err != nil { - progress.Error(err.Error()) - return fmt.Errorf("invalid provided flags: %w", err) + if progress.CanRunBubbleTea { + err = ValidateProvidedFlags(cliFlags.GitProvider) + if err != nil { + progress.Error(err.Error()) + return fmt.Errorf("invalid provided flags: %w", err) + } } clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete") @@ -111,9 +113,7 @@ func createVultr(cmd *cobra.Command, _ []string) error { } func ValidateProvidedFlags(gitProvider string) error { - if progress.CanRunBubbleTea { - progress.AddStep("Validate provided flags") - } + progress.AddStep("Validate provided flags") if os.Getenv("VULTR_API_KEY") == "" { return fmt.Errorf("your VULTR_API_KEY variable is unset - please set it before continuing") @@ -140,8 +140,7 @@ func ValidateProvidedFlags(gitProvider string) error { log.Info().Msgf("%q %s", "gitlab.com", key.Type()) } - if progress.CanRunBubbleTea { - progress.CompleteStep("Validate provided flags") - } + progress.CompleteStep("Validate provided flags") + return nil }