Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hanging commands #1904

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}

CristhianF7 marked this conversation as resolved.
Show resolved Hide resolved
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()
}