Skip to content

Commit

Permalink
fix validate flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jokestax committed Nov 11, 2024
1 parent 73afd9d commit a77db5f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 64 deletions.
18 changes: 8 additions & 10 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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
}
19 changes: 9 additions & 10 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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") == "" {
Expand All @@ -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
}
10 changes: 6 additions & 4 deletions cmd/azure/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
20 changes: 10 additions & 10 deletions cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") == "" {
Expand Down Expand Up @@ -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
}
19 changes: 9 additions & 10 deletions cmd/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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
}
19 changes: 9 additions & 10 deletions cmd/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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
}

0 comments on commit a77db5f

Please sign in to comment.