Skip to content

Commit

Permalink
handle zcli version check on home command
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Khare <khareyash05@gmail.com>
  • Loading branch information
khareyash05 committed Nov 11, 2024
1 parent faa63c6 commit 7c075e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"context"
"fmt"
"os"
"os/exec"

"github.com/zeropsio/zcli/src/cmd/scope"
"github.com/zeropsio/zcli/src/cmdBuilder"
Expand Down Expand Up @@ -36,13 +38,25 @@ func rootCmd() *cmdBuilder.Cmd {
AddChildrenCmd(supportCmd()).
AddChildrenCmd(updateCmd()).
GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error {
// run the zcli update command

homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to get home directory: %v", err)
}

zcliPath := fmt.Sprintf("%s/.local/bin/zcli", homeDir)
cmd := exec.CommandContext(ctx, zcliPath, "update")
cmd.Stdout = cmdData.Stdout.GetWriter()
cmd.Stdin = os.Stdin
fmt.Println(cmd.Stdout)
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to execute 'zcli update': %v", err)
}

cmdData.Stdout.PrintLines(
i18n.T(i18n.GuestWelcome),
printer.EmptyLine,
)

// print the default command help
cmdData.PrintHelp()

return nil
Expand Down
4 changes: 4 additions & 0 deletions src/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ func Style(s lipgloss.Style, text string) string {
}
return s.Render(text)
}

func (p *Printer) GetWriter() io.Writer {
return p.out
}

0 comments on commit 7c075e4

Please sign in to comment.