Skip to content

Commit

Permalink
Removing bubbletea.
Browse files Browse the repository at this point in the history
patrickdappollonio committed Dec 16, 2024
1 parent 9ebfa2e commit 98bcff0
Showing 6 changed files with 42 additions and 88 deletions.
4 changes: 0 additions & 4 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,3 @@ var infoCmd = &cobra.Command{
return nil
},
}

func init() {
rootCmd.AddCommand(infoCmd)
}
4 changes: 0 additions & 4 deletions cmd/logs.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,3 @@ var logsCmd = &cobra.Command{
return nil
},
}

func init() {
rootCmd.AddCommand(logsCmd)
}
4 changes: 0 additions & 4 deletions cmd/reset.go
Original file line number Diff line number Diff line change
@@ -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) {
59 changes: 24 additions & 35 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -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()

Check failure on line 59 in cmd/root.go

GitHub Actions / build

error returned from external package is unwrapped: sig: func (*github.com/spf13/cobra.Command).Execute() error (wrapcheck)
}
4 changes: 0 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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",
55 changes: 18 additions & 37 deletions main.go
Original file line number Diff line number Diff line change
@@ -15,36 +15,30 @@ 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"
"golang.org/x/exp/slices"
)

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,36 +72,33 @@ 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)

// * 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)
}
}

// * create log directory if it doesn't exist
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)
}
}

// * create session log file
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()

Check failure on line 127 in main.go

GitHub Actions / build

error returned from external package is unwrapped: sig: func github.com/konstructio/kubefirst/cmd.Execute() error (wrapcheck)
}

0 comments on commit 98bcff0

Please sign in to comment.