Skip to content

Commit

Permalink
fix: hanging commands (#1904)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Nov 9, 2023
1 parent 2e99ef7 commit 360973a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmd/k3d/mkcert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package k3d
import (
"fmt"

"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/runtime/pkg/helpers"
"github.com/kubefirst/runtime/pkg/k3d"
"github.com/kubefirst/runtime/pkg/k8s"
Expand Down Expand Up @@ -51,6 +52,7 @@ func mkCert(cmd *cobra.Command, args []string) error {
}

log.Infof("Certificate generated. You can use it with an app by setting `tls.secretName: %s-tls` on a Traefik IngressRoute.", appNameFlag)
progress.Progress.Quit()

return nil
}
3 changes: 3 additions & 0 deletions cmd/k3d/root-credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

"github.com/kubefirst/kubefirst-api/pkg/credentials"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/runtime/pkg/k3d"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -63,5 +64,7 @@ func getK3dRootCredentials(cmd *cobra.Command, args []string) error {
return err
}

progress.Progress.Quit()

return nil
}
3 changes: 3 additions & 0 deletions cmd/k3d/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

vaultapi "github.com/hashicorp/vault/api"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/runtime/pkg/helpers"
"github.com/kubefirst/runtime/pkg/k3d"
"github.com/kubefirst/runtime/pkg/k8s"
Expand Down Expand Up @@ -112,6 +113,8 @@ func unsealVault(cmd *cobra.Command, args []string) error {
return fmt.Errorf("vault is already unsealed")
}

progress.Progress.Quit()

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/letsencrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

"github.com/kubefirst/kubefirst-api/pkg/certificates"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,6 +42,7 @@ func status() *cobra.Command {
if err != nil {
fmt.Println(err)
}
progress.Progress.Quit()
},
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"
"time"

"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/runtime/pkg"
"github.com/kubefirst/runtime/pkg/helpers"
"github.com/kubefirst/runtime/pkg/progressPrinter"
Expand Down Expand Up @@ -131,6 +132,7 @@ func runReset() error {

progressPrinter.IncrementTracker("removing-platform-content", 1)
time.Sleep(time.Second * 2)
progress.Progress.Quit()

return nil
}
8 changes: 7 additions & 1 deletion internal/progress/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ func createErrorLog(message string) errorMsg {
func DisplayLogHints(estimatedTime int) {
logFile := viper.GetString("k1-paths.log-file")
cloudProvider := viper.GetString("kubefirst.cloud-provider")

documentationLink := "https://docs.kubefirst.io/"
if cloudProvider != "" {
documentationLink = documentationLink + cloudProvider + `/quick-start/install/cli`
}

header := `
##
# Welcome to Kubefirst
### :bulb: To view verbose logs run below command in new terminal:
` + fmt.Sprintf("##### **tail -f -n +1 %s**", logFile) + `
### :blue_book: Documentation: https://docs.kubefirst.io/` + cloudProvider + `/quick-start/install/cli
### :blue_book: Documentation: ` + documentationLink + `
### :alarm_clock: Estimated time:` + fmt.Sprintf("`%s minutes` \n\n", strconv.Itoa(estimatedTime))

Expand Down
14 changes: 8 additions & 6 deletions internal/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (m progressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case successMsg:
m.successMessage = msg.message
m.successMessage = msg.message + "\n\n"
return m, tea.Quit

case startProvision:
Expand Down Expand Up @@ -108,11 +108,13 @@ func (m progressModel) View() string {
completedSteps = completedSteps + renderMessage(fmt.Sprintf(":white_check_mark: %s", m.completedSteps[i]))
}

return m.header + "\n\n" +
completedSteps +
m.nextStep + "\n\n" +
m.error + "\n\n"
if m.header != "" {
return m.header + "\n\n" +
completedSteps +
m.nextStep + "\n\n" +
m.error + "\n\n"
}
}

return m.successMessage + "\n\n"
return m.successMessage
}
29 changes: 25 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/rs/zerolog"
"golang.org/x/exp/slices"

"github.com/rs/zerolog/log"

Expand All @@ -24,6 +25,21 @@ import (
)

func main() {
argsWithProg := os.Args

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

if argsWithProg != nil {
for _, arg := range argsWithProg {
isBlackListed := slices.Contains(bubbleTeaBlacklist, arg)

if isBlackListed {
canRunBubbleTea = false
}
}
}

now := time.Now()
epoch := now.Unix()

Expand Down Expand Up @@ -85,11 +101,16 @@ func main() {
stdLog.Panicf("unable to set log-file-location, error is: %s", err)
}

progress.InitializeProgressTerminal()
if canRunBubbleTea {
progress.InitializeProgressTerminal()

go func() {
go func() {
cmd.Execute()
}()

progress.Progress.Run()
} else {
cmd.Execute()
}()
}

progress.Progress.Run()
}

0 comments on commit 360973a

Please sign in to comment.