Skip to content

Commit

Permalink
fix: bubbletea output for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 committed Nov 12, 2024
1 parent 49fe9d1 commit 4a202f2
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions cmd/akamai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
2 changes: 2 additions & 0 deletions cmd/aws/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,7 @@ func RootCredentials() *cobra.Command {
RunE: common.GetRootCredentials,
}

authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
1 change: 1 addition & 0 deletions cmd/azure/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the argocd password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
1 change: 1 addition & 0 deletions cmd/civo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "Copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "Copy the Kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "Copy the Vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
1 change: 1 addition & 0 deletions cmd/digitalocean/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
1 change: 1 addition & 0 deletions cmd/google/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
1 change: 1 addition & 0 deletions cmd/k3s/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
3 changes: 3 additions & 0 deletions cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

// additionalHelmFlags can optionally pass user-supplied flags to helm
var additionalHelmFlags []string
var ciFlag bool

func LaunchCommand() *cobra.Command {
launchCommand := &cobra.Command{
Expand Down Expand Up @@ -103,5 +104,7 @@ func launchDeleteCluster() *cobra.Command {
},
}

launchDeleteClusterCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return launchDeleteClusterCmd
}
1 change: 1 addition & 0 deletions cmd/vultr/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func RootCredentials() *cobra.Command {
authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "Copy the ArgoCD password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "Copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "Copy the vault password to the clipboard (optional)")
authCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")

return authCmd
}
1 change: 1 addition & 0 deletions internal/progress/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GetClusterInterval(clusterName string) tea.Cmd {
func AddSuccesMessage(cluster types.Cluster) tea.Cmd {
return tea.Tick(0, func(_ time.Time) tea.Msg {
successMessage := DisplaySuccessMessage(cluster)
printLine(successMessage.message)

return successMessage
})
Expand Down
28 changes: 18 additions & 10 deletions internal/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,31 @@ package progress

import (
"fmt"
"os"

tea "github.com/charmbracelet/bubbletea"
"github.com/konstructio/kubefirst-api/pkg/types"
"github.com/spf13/viper"
)

var (
Progress *tea.Program
CanRunBubbleTea bool
Progress *tea.Program
isCiExecution bool
)

//nolint:revive // will be removed after refactoring
func NewModel() progressModel {

Check failure on line 23 in internal/progress/progress.go

View workflow job for this annotation

GitHub Actions / build

unexported-return: exported func NewModel returns unexported type progress.progressModel, which can be annoying to use (revive)
return progressModel{
isProvisioned: false,
}
}

func DiableBubbleTeaExecution() {
CanRunBubbleTea = false
}

// Bubbletea functions
func InitializeProgressTerminal() {
if CanRunBubbleTea {
func InitializeProgressTerminal(isCi bool) {
isCiExecution = isCi
if !isCiExecution {
Progress = tea.NewProgram(NewModel())
} else {
Progress = tea.NewProgram(NewModel(), tea.WithoutRenderer())
Progress = tea.NewProgram(NewModel(), tea.WithOutput(os.Stdout), tea.WithoutRenderer())
}
}

Expand All @@ -54,10 +51,12 @@ func (m progressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

case headerMsg:
printLine(msg.message)
m.header = msg.message
return m, nil

case addStep:
printLine(msg.message)
m.nextStep = msg.message
return m, nil

Expand All @@ -67,10 +66,12 @@ func (m progressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil

case errorMsg:
printLine(msg.message)
m.error = msg.message
return m, tea.Quit

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

Expand All @@ -86,6 +87,7 @@ func (m progressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

if m.provisioningCluster.Status == "error" {
errorMessage := createErrorLog(m.provisioningCluster.LastCondition)
printLine(errorMessage.message)
m.error = errorMessage.message
return m, tea.Quit
}
Expand Down Expand Up @@ -129,3 +131,9 @@ func (m progressModel) View() string {

return m.successMessage
}

func printLine(message string) {
if isCiExecution {
fmt.Fprintln(os.Stdout, message)
}
}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
func main() {
argsWithProg := os.Args

bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs", "--ci"}
bubbleTeaBlacklist := []string{"completion", "help", "--help", "-h", "quota", "logs"}
isCiExecution := slices.Contains(argsWithProg, "--ci")
canRunBubbleTea := true

for _, arg := range argsWithProg {
Expand Down Expand Up @@ -134,7 +135,7 @@ func main() {
}

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

go func() {
cmd.Execute()
Expand All @@ -143,6 +144,5 @@ func main() {
progress.Progress.Run()
} else {
cmd.Execute()
progress.DiableBubbleTeaExecution()
}
}

0 comments on commit 4a202f2

Please sign in to comment.