Skip to content

Commit

Permalink
feat:bypass bubbletea
Browse files Browse the repository at this point in the history
  • Loading branch information
jokestax committed Sep 19, 2024
1 parent 1dc4e0c commit fe26630
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 106 deletions.
35 changes: 20 additions & 15 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func createAkamai(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")

if progress.CanRunBubbleTea {
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 @@ -111,22 +114,24 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("failed to fetch github host key: %w", err)
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("failed to fetch github host key: %w", err)
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("failed to fetch gitlab host key: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("failed to fetch gitlab host key: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")
progress.CompleteStep("Validate provided flags")
}

return nil
}
35 changes: 20 additions & 15 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ func createAws(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {

Check failure on line 135 in cmd/aws/create.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)
progress.AddStep("Validate provided flags")

if progress.CanRunBubbleTea {
progress.AddStep("Validate provided flags")
}

// Validate required environment variables for dns provider
if dnsProviderFlag == "cloudflare" {
Expand All @@ -142,22 +145,24 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy: %w", err)
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
progress.CompleteStep("Validate provided flags")

progress.CompleteStep("Validate provided flags")
}

Check failure on line 165 in cmd/aws/create.go

View workflow job for this annotation

GitHub Actions / build

unnecessary trailing newline (whitespace)

return nil
}
35 changes: 20 additions & 15 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func createCivo(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")

if progress.CanRunBubbleTea {
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 All @@ -115,22 +118,24 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy")
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("github.com %q", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("gitlab.com %q", key.Type())
}
log.Info().Msgf("github.com %q", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("gitlab.com %q", key.Type())
}

progress.CompleteStep("Validate provided flags")
progress.CompleteStep("Validate provided flags")
}

return nil
}
36 changes: 21 additions & 15 deletions cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func createDigitalocean(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")

if progress.CanRunBubbleTea {
progress.AddStep("Validate provided flags")

}

Check failure on line 118 in cmd/digitalocean/create.go

View workflow job for this annotation

GitHub Actions / build

unnecessary trailing newline (whitespace)

// Validate required environment variables for dns provider
if dnsProviderFlag == "cloudflare" {
Expand All @@ -126,22 +130,24 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy")
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")
progress.CompleteStep("Validate provided flags")
}

return nil
}
35 changes: 20 additions & 15 deletions cmd/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func createGoogle(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")

if progress.CanRunBubbleTea {
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 @@ -116,22 +119,24 @@ func ValidateProvidedFlags(gitProvider string) error {
return fmt.Errorf("could not open GOOGLE_APPLICATION_CREDENTIALS file: %w", err)
}

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy: %w", err)
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
progress.CompleteStep("Validate provided flags")

progress.CompleteStep("Validate provided flags")
}

return nil
}
35 changes: 20 additions & 15 deletions cmd/k3s/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,29 @@ func createK3s(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {

Check failure on line 116 in cmd/k3s/create.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)
progress.AddStep("Validate provided flags")

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
if progress.CanRunBubbleTea {
progress.AddStep("Validate provided flags")
}

progress.CompleteStep("Validate provided flags")
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy")
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

progress.CompleteStep("Validate provided flags")
}

return nil
}
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package cmd

import (
"fmt"
"os"

"github.com/konstructio/kubefirst-api/pkg/configs"
"github.com/konstructio/kubefirst-api/pkg/progressPrinter"
Expand Down Expand Up @@ -50,7 +51,11 @@ func Execute() {
fmt.Println("Error occurred during command execution:", err)
fmt.Println("If a detailed error message was available, please make the necessary corrections before retrying.")
fmt.Println("You can re-run the last command to try the operation again.")
progress.Progress.Quit()
if progress.CanRunBubbleTea {
progress.Progress.Quit()
} else {
os.Exit(1)
}
}
}

Expand Down
35 changes: 21 additions & 14 deletions cmd/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func createVultr(cmd *cobra.Command, _ []string) error {
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")

if progress.CanRunBubbleTea {
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 @@ -123,21 +127,24 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy: %w", err)
if progress.CanRunBubbleTea {
switch gitProvider {
case "github":
key, err := internalssh.GetHostKey("github.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}
log.Info().Msgf("%q %s", "github.com", key.Type())
case "gitlab":
key, err := internalssh.GetHostKey("gitlab.com")
if err != nil {
return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy: %w", err)
}
log.Info().Msgf("%q %s", "gitlab.com", key.Type())

progress.CompleteStep("Validate provided flags")
}

progress.CompleteStep("Validate provided flags")
return nil
}
6 changes: 6 additions & 0 deletions internal/progress/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ func DisplayCredentials(cluster types.Cluster) {

func AddStep(message string) {
renderedMessage := createStep(fmt.Sprintf("%s %s", ":dizzy:", message))

if !CanRunBubbleTea {
fmt.Println(renderedMessage)
return
}

Progress.Send(renderedMessage)
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func main() {
argsWithProg := os.Args

bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs", "ci"}
bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs", "--ci"}
canRunBubbleTea := true

for _, arg := range argsWithProg {
Expand Down

0 comments on commit fe26630

Please sign in to comment.