From 98bcff0a7d3ec25233e4cd494f8299df573499be Mon Sep 17 00:00:00 2001 From: Patrick D'appollonio <930925+patrickdappollonio@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:39:59 -0500 Subject: [PATCH] Removing bubbletea. --- cmd/info.go | 4 ---- cmd/logs.go | 4 ---- cmd/reset.go | 4 ---- cmd/root.go | 59 ++++++++++++++++++++------------------------------ cmd/version.go | 4 ---- main.go | 55 +++++++++++++++------------------------------- 6 files changed, 42 insertions(+), 88 deletions(-) diff --git a/cmd/info.go b/cmd/info.go index f99d4ecf..5495e723 100755 --- a/cmd/info.go +++ b/cmd/info.go @@ -49,7 +49,3 @@ var infoCmd = &cobra.Command{ return nil }, } - -func init() { - rootCmd.AddCommand(infoCmd) -} diff --git a/cmd/logs.go b/cmd/logs.go index 426db037..3500006e 100755 --- a/cmd/logs.go +++ b/cmd/logs.go @@ -44,7 +44,3 @@ var logsCmd = &cobra.Command{ return nil }, } - -func init() { - rootCmd.AddCommand(logsCmd) -} diff --git a/cmd/reset.go b/cmd/reset.go index 7264c252..c41b2944 100755 --- a/cmd/reset.go +++ b/cmd/reset.go @@ -76,10 +76,6 @@ var resetCmd = &cobra.Command{ }, } -func init() { - rootCmd.AddCommand(resetCmd) -} - // parseConfigEntryKubefirstChecks gathers the kubefirst-checks section of the Viper // config file and parses as a map[string]bool func parseConfigEntryKubefirstChecks(checks map[string]interface{}) (map[string]bool, error) { diff --git a/cmd/root.go b/cmd/root.go index 3a9b4059..6bb92711 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,52 +10,33 @@ import ( "fmt" "github.com/konstructio/kubefirst-api/pkg/configs" - "github.com/konstructio/kubefirst-api/pkg/progressPrinter" "github.com/konstructio/kubefirst/cmd/aws" "github.com/konstructio/kubefirst/cmd/civo" "github.com/konstructio/kubefirst/cmd/digitalocean" "github.com/konstructio/kubefirst/cmd/k3d" - "github.com/konstructio/kubefirst/internal/common" - "github.com/konstructio/kubefirst/internal/progress" "github.com/spf13/cobra" ) -// rootCmd represents the base command when called without any subcommands -var rootCmd = &cobra.Command{ - Use: "kubefirst", - Short: "kubefirst management cluster installer base command", - Long: `kubefirst management cluster installer provisions an - open source application delivery platform in under an hour. - checkout the docs at https://kubefirst.konstruct.io/docs/.`, - PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { - // wire viper config for flags for all commands - return configs.InitializeViperConfig(cmd) - }, - Run: func(_ *cobra.Command, _ []string) { - fmt.Println("To learn more about kubefirst, run:") - fmt.Println(" kubefirst help") - progress.Progress.Quit() - }, -} - // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute() { - // This will allow all child commands to have informUser available for free. - // Refers: https://github.com/konstructio/runtime/issues/525 - // Before removing next line, please read ticket above. - common.CheckForVersionUpdate() - progressPrinter.GetInstance() - if err := rootCmd.Execute(); err != nil { - 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() +func Execute() error { + // rootCmd represents the base command when called without any subcommands + rootCmd := &cobra.Command{ + Use: "kubefirst", + Short: "kubefirst management cluster installer base command", + Long: `kubefirst management cluster installer provisions an + open source application delivery platform in under an hour. + checkout the docs at https://kubefirst.konstruct.io/docs/.`, + PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { + // wire viper config for flags for all commands + return configs.InitializeViperConfig(cmd) + }, + Run: func(_ *cobra.Command, _ []string) { + fmt.Println("To learn more about kubefirst, run:") + fmt.Println(" kubefirst help") + }, } -} -func init() { - cobra.OnInitialize() rootCmd.SilenceUsage = true rootCmd.AddCommand( betaCmd, @@ -67,5 +48,13 @@ func init() { LaunchCommand(), LetsEncryptCommand(), TerraformCommand(), + + // Subcommands + resetCmd, + infoCmd, + logsCmd, + versionCmd, ) + + return rootCmd.Execute() } diff --git a/cmd/version.go b/cmd/version.go index f446bb0e..b5c64c80 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -12,10 +12,6 @@ import ( "github.com/spf13/cobra" ) -func init() { - rootCmd.AddCommand(versionCmd) -} - var versionCmd = &cobra.Command{ Use: "version", Short: "print the version number for kubefirst-cli", diff --git a/main.go b/main.go index e030707e..15892a9f 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "github.com/konstructio/kubefirst-api/pkg/configs" utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/cmd" - "github.com/konstructio/kubefirst/internal/progress" + "github.com/konstructio/kubefirst/internal/common" zeroLog "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/viper" @@ -23,28 +23,22 @@ import ( ) func main() { - argsWithProg := os.Args - - bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs"} - canRunBubbleTea := true - - for _, arg := range argsWithProg { - isBlackListed := slices.Contains(bubbleTeaBlacklist, arg) - - if isBlackListed { - canRunBubbleTea = false - } + if err := run(); err != nil { + fmt.Fprintln(os.Stderr, "error:", err.Error()) + os.Exit(1) } +} + +func run() error { + argsWithProg := os.Args config, err := configs.ReadConfig() if err != nil { - log.Error().Msgf("failed to read config: %v", err) - return + return fmt.Errorf("failed to read config: %w", err) } if err := utils.SetupViper(config, true); err != nil { - log.Error().Msgf("failed to setup Viper: %v", err) - return + return fmt.Errorf("failed to setup Viper: %w", err) } now := time.Now() @@ -78,8 +72,7 @@ func main() { homePath, err := os.UserHomeDir() if err != nil { - log.Error().Msgf("failed to get user home directory: %v", err) - return + return fmt.Errorf("failed to get user home directory: %w", err) } k1Dir := fmt.Sprintf("%s/.k1", homePath) @@ -87,8 +80,7 @@ func main() { // * create k1Dir if it doesn't exist if _, err := os.Stat(k1Dir); os.IsNotExist(err) { if err := os.MkdirAll(k1Dir, os.ModePerm); err != nil { - log.Error().Msgf("error creating directory %q: %v", k1Dir, err) - return + return fmt.Errorf("error creating directory %q: %w", k1Dir, err) } } @@ -96,8 +88,7 @@ func main() { logsFolder := fmt.Sprintf("%s/logs", k1Dir) if _, err := os.Stat(logsFolder); os.IsNotExist(err) { if err := os.Mkdir(logsFolder, 0o700); err != nil { - log.Error().Msgf("error creating logs directory: %v", err) - return + return fmt.Errorf("error creating logs directory: %w", err) } } @@ -105,9 +96,9 @@ func main() { logfile := fmt.Sprintf("%s/%s", logsFolder, logfileName) logFileObj, err := utils.OpenLogFile(logfile) if err != nil { - log.Error().Msgf("unable to store log location, error is: %v - please verify the current user has write access to this directory", err) - return + return fmt.Errorf("unable to store log location: %w - please verify the current user has write access to this directory", err) } + logFileObj.Close() // handle file close request defer func(logFileObj *os.File) { @@ -129,19 +120,9 @@ func main() { viper.Set("k1-paths.log-file-name", logfileName) if err := viper.WriteConfig(); err != nil { - log.Error().Msgf("failed to write config: %v", err) - return + return fmt.Errorf("failed to write viper config: %w", err) } - if canRunBubbleTea { - progress.InitializeProgressTerminal() - - go func() { - cmd.Execute() - }() - - progress.Progress.Run() - } else { - cmd.Execute() - } + common.CheckForVersionUpdate() + return cmd.Execute() }