From 1c8cc37d07cd7d9b3bd1c53052f768b081aec711 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Mon, 11 Nov 2024 22:53:14 +0530 Subject: [PATCH 1/7] feat: zcli update Signed-off-by: Yash Khare --- src/cmd/root.go | 1 + src/cmd/update.go | 134 ++++++++++++++++++++++++++++++++++++++++++++++ src/i18n/en.go | 4 ++ src/i18n/i18n.go | 4 ++ 4 files changed, 143 insertions(+) create mode 100644 src/cmd/update.go diff --git a/src/cmd/root.go b/src/cmd/root.go index 0b8bb536..86136150 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -34,6 +34,7 @@ func rootCmd() *cmdBuilder.Cmd { AddChildrenCmd(servicePushCmd()). AddChildrenCmd(envCmd()). AddChildrenCmd(supportCmd()). + AddChildrenCmd(updateCmd()). GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error { cmdData.Stdout.PrintLines( i18n.T(i18n.GuestWelcome), diff --git a/src/cmd/update.go b/src/cmd/update.go new file mode 100644 index 00000000..aab35101 --- /dev/null +++ b/src/cmd/update.go @@ -0,0 +1,134 @@ +package cmd + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net" + "net/http" + "os" + "os/exec" + "runtime" + "time" + + "github.com/zeropsio/zcli/src/cmdBuilder" + "github.com/zeropsio/zcli/src/i18n" +) + +// other necessary imports + +func updateCmd() *cmdBuilder.Cmd { + // check existing zcli version + return cmdBuilder.NewCmd(). + Use("update"). + Short(i18n.T(i18n.CmdDescUpdate)). + HelpFlag(i18n.T(i18n.CmdHelpUpdate)). + GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error { + // print the current version of zcli + latestVersion, err := getLatestGitHubRelease(ctx) + if err != nil { + return err + } + + if latestVersion.TagName != version { + fmt.Println("There is a new version available:", latestVersion.TagName) + fmt.Println("Do you want to update? (y/n)") + var input string + fmt.Scanln(&input) + + if input == "y" { + fmt.Println("Updating zcli...") + + // Set the target based on system architecture + var target string + switch runtime.GOOS + " " + runtime.GOARCH { + case "darwin amd64": + target = "darwin-amd64" + case "darwin arm64": + target = "darwin-arm64" + case "linux 386": + target = "linux-i386" + default: + target = "linux-amd64" + } + + // Determine the URI for the download based on the target + var zcliURI = fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) + + // Define installation path + binDir := os.ExpandEnv("$HOME/.local/bin") + binPath := fmt.Sprintf("%s/zcli", binDir) + + // Create binDir if it doesn't exist + if _, err := os.Stat(binDir); os.IsNotExist(err) { + if err := os.MkdirAll(binDir, 0755); err != nil { + return fmt.Errorf("failed to create directory %s: %v", binDir, err) + } + } + + // Download zcli binary + curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) + cmd := exec.Command("sh", "-c", curlCmd) + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to download zcli: %v", err) + } + + // Make binary executable + if err := os.Chmod(binPath, 0755); err != nil { + return fmt.Errorf("failed to make zcli executable: %v", err) + } + + fmt.Println("zCLI was installed successfully to", binPath) + } else { + fmt.Println("Update canceled.") + } + } else { + fmt.Println("You are using the latest version of zcli") + } + return nil + }) +} + +type GitHubRelease struct { + TagName string `json:"tag_name"` + Body string `json:"body"` +} + +func getLatestGitHubRelease(ctx context.Context) (GitHubRelease, error) { + // GitHub repository details + repoOwner := "zeropsio" + repoName := "zcli" + + apiURL := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", repoOwner, repoName) + + client := http.Client{ + Timeout: 4 * time.Second, + } + + req, err := http.NewRequestWithContext(ctx, "GET", apiURL, nil) + if err != nil { + return GitHubRelease{}, err + } + + resp, err := client.Do(req) + if err != nil { + var netErr net.Error + if errors.As(err, &netErr) && netErr.Timeout() { + return GitHubRelease{}, nil + } + return GitHubRelease{}, err + } + defer func() { + if err := resp.Body.Close(); err != nil { + fmt.Println("erorr") + } + }() + + var release GitHubRelease + if err := json.NewDecoder(resp.Body).Decode(&release); err != nil { + return GitHubRelease{}, err + } + return release, nil +} diff --git a/src/i18n/en.go b/src/i18n/en.go index 1053ae3e..f3e7b632 100644 --- a/src/i18n/en.go +++ b/src/i18n/en.go @@ -183,6 +183,10 @@ and your %s.`, CmdDescStatusShowDebugLogs: "Shows zCLI debug logs", DebugLogsNotFound: "Debug logs not found", + // update + CmdHelpUpdate :"the update command", + CmdDescUpdate: "Updates zCLI to the latest version", + // version CmdHelpVersion: "the version command.", CmdDescVersion: "Shows the current zCLI version", diff --git a/src/i18n/i18n.go b/src/i18n/i18n.go index 55091c49..b933aaed 100644 --- a/src/i18n/i18n.go +++ b/src/i18n/i18n.go @@ -168,6 +168,10 @@ const ( CmdDescStatusShowDebugLogs = "CmdDescStatusShowDebugLogs" DebugLogsNotFound = "DebugLogsNotFound" + // update + CmdHelpUpdate = "CmdHelpUpdate" + CmdDescUpdate = "CmdDescUpdate" + // version CmdHelpVersion = "CmdHelpVersion" CmdDescVersion = "CmdDescVersion" From faa63c66312a970f778cb6ba0d5d8c5eb74c2b10 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Mon, 11 Nov 2024 23:03:59 +0530 Subject: [PATCH 2/7] handle dev env setup Signed-off-by: Yash Khare --- src/cmd/root.go | 1 + src/cmd/update.go | 116 ++++++++++++++++++++++++---------------------- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index 86136150..ad18f579 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -36,6 +36,7 @@ func rootCmd() *cmdBuilder.Cmd { AddChildrenCmd(supportCmd()). AddChildrenCmd(updateCmd()). GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error { + // run the zcli update command cmdData.Stdout.PrintLines( i18n.T(i18n.GuestWelcome), printer.EmptyLine, diff --git a/src/cmd/update.go b/src/cmd/update.go index aab35101..41f800f3 100644 --- a/src/cmd/update.go +++ b/src/cmd/update.go @@ -26,66 +26,70 @@ func updateCmd() *cmdBuilder.Cmd { HelpFlag(i18n.T(i18n.CmdHelpUpdate)). GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error { // print the current version of zcli - latestVersion, err := getLatestGitHubRelease(ctx) - if err != nil { - return err - } - - if latestVersion.TagName != version { - fmt.Println("There is a new version available:", latestVersion.TagName) - fmt.Println("Do you want to update? (y/n)") - var input string - fmt.Scanln(&input) - - if input == "y" { - fmt.Println("Updating zcli...") - - // Set the target based on system architecture - var target string - switch runtime.GOOS + " " + runtime.GOARCH { - case "darwin amd64": - target = "darwin-amd64" - case "darwin arm64": - target = "darwin-arm64" - case "linux 386": - target = "linux-i386" - default: - target = "linux-amd64" - } - - // Determine the URI for the download based on the target - var zcliURI = fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) - - // Define installation path - binDir := os.ExpandEnv("$HOME/.local/bin") - binPath := fmt.Sprintf("%s/zcli", binDir) - - // Create binDir if it doesn't exist - if _, err := os.Stat(binDir); os.IsNotExist(err) { - if err := os.MkdirAll(binDir, 0755); err != nil { - return fmt.Errorf("failed to create directory %s: %v", binDir, err) + if version != "" { + latestVersion, err := getLatestGitHubRelease(ctx) + if err != nil { + return err + } + + if latestVersion.TagName != version { + fmt.Println("There is a new version available:", latestVersion.TagName) + fmt.Println("Do you want to update? (y/n)") + var input string + fmt.Scanln(&input) + + if input == "y" { + fmt.Println("Updating zcli...") + + // Set the target based on system architecture + var target string + switch runtime.GOOS + " " + runtime.GOARCH { + case "darwin amd64": + target = "darwin-amd64" + case "darwin arm64": + target = "darwin-arm64" + case "linux 386": + target = "linux-i386" + default: + target = "linux-amd64" } + + // Determine the URI for the download based on the target + var zcliURI = fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) + + // Define installation path + binDir := os.ExpandEnv("$HOME/.local/bin") + binPath := fmt.Sprintf("%s/zcli", binDir) + + // Create binDir if it doesn't exist + if _, err := os.Stat(binDir); os.IsNotExist(err) { + if err := os.MkdirAll(binDir, 0755); err != nil { + return fmt.Errorf("failed to create directory %s: %v", binDir, err) + } + } + + // Download zcli binary + curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) + cmd := exec.Command("sh", "-c", curlCmd) + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to download zcli: %v", err) + } + + // Make binary executable + if err := os.Chmod(binPath, 0755); err != nil { + return fmt.Errorf("failed to make zcli executable: %v", err) + } + + fmt.Println("zCLI was installed successfully to", binPath) + } else { + fmt.Println("Update canceled.") } - - // Download zcli binary - curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) - cmd := exec.Command("sh", "-c", curlCmd) - - if err := cmd.Run(); err != nil { - return fmt.Errorf("failed to download zcli: %v", err) - } - - // Make binary executable - if err := os.Chmod(binPath, 0755); err != nil { - return fmt.Errorf("failed to make zcli executable: %v", err) - } - - fmt.Println("zCLI was installed successfully to", binPath) } else { - fmt.Println("Update canceled.") + fmt.Println("You are using the latest version of zcli") } - } else { - fmt.Println("You are using the latest version of zcli") + }else{ + fmt.Println("You are using the development environment of zcli") } return nil }) From 7c075e46bacabeecefff3b8f76f6431ec8ae9b05 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Mon, 11 Nov 2024 23:32:44 +0530 Subject: [PATCH 3/7] handle zcli version check on home command Signed-off-by: Yash Khare --- src/cmd/root.go | 20 +++++++++++++++++--- src/printer/printer.go | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index ad18f579..e021b508 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -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" @@ -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 diff --git a/src/printer/printer.go b/src/printer/printer.go index 8a0108fb..4c1afd3d 100644 --- a/src/printer/printer.go +++ b/src/printer/printer.go @@ -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 +} \ No newline at end of file From d736680a2401c817a34eedc86adba4ccff1ef9c8 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Mon, 11 Nov 2024 23:34:00 +0530 Subject: [PATCH 4/7] add comments Signed-off-by: Yash Khare --- src/cmd/root.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cmd/root.go b/src/cmd/root.go index e021b508..0d1a97d5 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -57,6 +57,8 @@ func rootCmd() *cmdBuilder.Cmd { i18n.T(i18n.GuestWelcome), printer.EmptyLine, ) + + // print the default command help cmdData.PrintHelp() return nil From 0cfaf6cfbe560611fc8aba67c0739a87055cd911 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Mon, 11 Nov 2024 23:43:29 +0530 Subject: [PATCH 5/7] modularize code Signed-off-by: Yash Khare --- src/cmd/root.go | 1 - src/cmd/update.go | 90 +++++++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index 0d1a97d5..6fc92af5 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -48,7 +48,6 @@ func rootCmd() *cmdBuilder.Cmd { 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) } diff --git a/src/cmd/update.go b/src/cmd/update.go index 41f800f3..68654bb5 100644 --- a/src/cmd/update.go +++ b/src/cmd/update.go @@ -39,49 +39,11 @@ func updateCmd() *cmdBuilder.Cmd { fmt.Scanln(&input) if input == "y" { - fmt.Println("Updating zcli...") - - // Set the target based on system architecture - var target string - switch runtime.GOOS + " " + runtime.GOARCH { - case "darwin amd64": - target = "darwin-amd64" - case "darwin arm64": - target = "darwin-arm64" - case "linux 386": - target = "linux-i386" - default: - target = "linux-amd64" - } - - // Determine the URI for the download based on the target - var zcliURI = fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) - - // Define installation path - binDir := os.ExpandEnv("$HOME/.local/bin") - binPath := fmt.Sprintf("%s/zcli", binDir) - - // Create binDir if it doesn't exist - if _, err := os.Stat(binDir); os.IsNotExist(err) { - if err := os.MkdirAll(binDir, 0755); err != nil { - return fmt.Errorf("failed to create directory %s: %v", binDir, err) - } + target := determineTargetArchitecture() + if err := downloadAndInstallZCLI(ctx, target); err != nil { + return err } - - // Download zcli binary - curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) - cmd := exec.Command("sh", "-c", curlCmd) - - if err := cmd.Run(); err != nil { - return fmt.Errorf("failed to download zcli: %v", err) - } - - // Make binary executable - if err := os.Chmod(binPath, 0755); err != nil { - return fmt.Errorf("failed to make zcli executable: %v", err) - } - - fmt.Println("zCLI was installed successfully to", binPath) + fmt.Println("zCLI was updated successfully to",latestVersion.TagName) } else { fmt.Println("Update canceled.") } @@ -136,3 +98,47 @@ func getLatestGitHubRelease(ctx context.Context) (GitHubRelease, error) { } return release, nil } + +func determineTargetArchitecture() string { + switch runtime.GOOS + " " + runtime.GOARCH { + case "darwin amd64": + return "darwin-amd64" + case "darwin arm64": + return "darwin-arm64" + case "linux 386": + return "linux-i386" + default: + return "linux-amd64" + } +} + +func downloadAndInstallZCLI(ctx context.Context, target string) error { + homeDir, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("failed to get home directory: %v", err) + } + + binDir := fmt.Sprintf("%s/.local/bin", homeDir) + binPath := fmt.Sprintf("%s/zcli", binDir) + + if _, err := os.Stat(binDir); os.IsNotExist(err) { + if err := os.MkdirAll(binDir, 0755); err != nil { + return fmt.Errorf("failed to create directory %s: %v", binDir, err) + } + } + + zcliURI := fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) + curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) + cmd := exec.CommandContext(ctx, "sh", "-c", curlCmd) + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to download zcli: %v", err) + } + + if err := os.Chmod(binPath, 0755); err != nil { + return fmt.Errorf("failed to make zcli executable: %v", err) + } + + fmt.Printf("zCLI was installed successfully to %s\n", binPath) + return nil +} From 4cc94bef4983af6ca2b10e050ac5383bb833bbf8 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Tue, 12 Nov 2024 09:07:17 +0530 Subject: [PATCH 6/7] handle linter errors Signed-off-by: Yash Khare --- .../handler_findFilesByRules_test.go | 1 + .../handler_findGitFiles_test.go | 1 + src/cmd/root.go | 6 +- src/cmd/update.go | 84 +++++++++---------- src/i18n/en.go | 2 +- src/printer/printer.go | 4 +- 6 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/archiveClient/handler_findFilesByRules_test.go b/src/archiveClient/handler_findFilesByRules_test.go index f66c29e9..b4e35915 100644 --- a/src/archiveClient/handler_findFilesByRules_test.go +++ b/src/archiveClient/handler_findFilesByRules_test.go @@ -1,4 +1,5 @@ //go:build exclude + package archiveClient import ( diff --git a/src/archiveClient/handler_findGitFiles_test.go b/src/archiveClient/handler_findGitFiles_test.go index eba2eca0..0ed05974 100644 --- a/src/archiveClient/handler_findGitFiles_test.go +++ b/src/archiveClient/handler_findGitFiles_test.go @@ -1,4 +1,5 @@ //go:build exclude + package archiveClient import ( diff --git a/src/cmd/root.go b/src/cmd/root.go index 6fc92af5..53aab3c3 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -43,15 +43,15 @@ func rootCmd() *cmdBuilder.Cmd { 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 + cmd.Stdin = os.Stdin 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, diff --git a/src/cmd/update.go b/src/cmd/update.go index 68654bb5..77ce1c54 100644 --- a/src/cmd/update.go +++ b/src/cmd/update.go @@ -31,26 +31,26 @@ func updateCmd() *cmdBuilder.Cmd { if err != nil { return err } - + if latestVersion.TagName != version { fmt.Println("There is a new version available:", latestVersion.TagName) fmt.Println("Do you want to update? (y/n)") var input string fmt.Scanln(&input) - + if input == "y" { target := determineTargetArchitecture() if err := downloadAndInstallZCLI(ctx, target); err != nil { return err } - fmt.Println("zCLI was updated successfully to",latestVersion.TagName) + fmt.Println("zCLI was updated successfully to", latestVersion.TagName) } else { fmt.Println("Update canceled.") } } else { fmt.Println("You are using the latest version of zcli") } - }else{ + } else { fmt.Println("You are using the development environment of zcli") } return nil @@ -100,45 +100,45 @@ func getLatestGitHubRelease(ctx context.Context) (GitHubRelease, error) { } func determineTargetArchitecture() string { - switch runtime.GOOS + " " + runtime.GOARCH { - case "darwin amd64": - return "darwin-amd64" - case "darwin arm64": - return "darwin-arm64" - case "linux 386": - return "linux-i386" - default: - return "linux-amd64" - } + switch runtime.GOOS + " " + runtime.GOARCH { + case "darwin amd64": + return "darwin-amd64" + case "darwin arm64": + return "darwin-arm64" + case "linux 386": + return "linux-i386" + default: + return "linux-amd64" + } } func downloadAndInstallZCLI(ctx context.Context, target string) error { - homeDir, err := os.UserHomeDir() - if err != nil { - return fmt.Errorf("failed to get home directory: %v", err) - } - - binDir := fmt.Sprintf("%s/.local/bin", homeDir) - binPath := fmt.Sprintf("%s/zcli", binDir) - - if _, err := os.Stat(binDir); os.IsNotExist(err) { - if err := os.MkdirAll(binDir, 0755); err != nil { - return fmt.Errorf("failed to create directory %s: %v", binDir, err) - } - } - - zcliURI := fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) - curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) - cmd := exec.CommandContext(ctx, "sh", "-c", curlCmd) - - if err := cmd.Run(); err != nil { - return fmt.Errorf("failed to download zcli: %v", err) - } - - if err := os.Chmod(binPath, 0755); err != nil { - return fmt.Errorf("failed to make zcli executable: %v", err) - } - - fmt.Printf("zCLI was installed successfully to %s\n", binPath) - return nil + homeDir, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("failed to get home directory: %w", err) + } + + binDir := fmt.Sprintf("%s/.local/bin", homeDir) + binPath := fmt.Sprintf("%s/zcli", binDir) + + if _, err := os.Stat(binDir); os.IsNotExist(err) { + if err := os.MkdirAll(binDir, 0755); err != nil { + return fmt.Errorf("failed to create directory %s: %w", binDir, err) + } + } + + zcliURI := fmt.Sprintf("https://github.com/zeropsio/zcli/releases/latest/download/zcli-%s", target) + curlCmd := fmt.Sprintf("curl --fail --location --progress-bar --output %s %s", binPath, zcliURI) + cmd := exec.CommandContext(ctx, "sh", "-c", curlCmd) + + if err := cmd.Run(); err != nil { + return fmt.Errorf("failed to download zcli: %w", err) + } + + if err := os.Chmod(binPath, 0755); err != nil { + return fmt.Errorf("failed to make zcli executable: %w", err) + } + + fmt.Printf("zCLI was installed successfully to %s\n", binPath) + return nil } diff --git a/src/i18n/en.go b/src/i18n/en.go index f3e7b632..19ebf2ea 100644 --- a/src/i18n/en.go +++ b/src/i18n/en.go @@ -184,7 +184,7 @@ and your %s.`, DebugLogsNotFound: "Debug logs not found", // update - CmdHelpUpdate :"the update command", + CmdHelpUpdate: "the update command", CmdDescUpdate: "Updates zCLI to the latest version", // version diff --git a/src/printer/printer.go b/src/printer/printer.go index 4c1afd3d..22480510 100644 --- a/src/printer/printer.go +++ b/src/printer/printer.go @@ -48,5 +48,5 @@ func Style(s lipgloss.Style, text string) string { } func (p *Printer) GetWriter() io.Writer { - return p.out -} \ No newline at end of file + return p.out +} From 8d580280db5d480b805d3b95932b79e029b70b42 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 14 Nov 2024 14:44:38 +0530 Subject: [PATCH 7/7] fixed linter issues --- src/cmd/root.go | 5 ++--- src/cmd/update.go | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index 53aab3c3..ab88433f 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -38,10 +38,9 @@ func rootCmd() *cmdBuilder.Cmd { AddChildrenCmd(supportCmd()). AddChildrenCmd(updateCmd()). GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error { - homeDir, err := os.UserHomeDir() if err != nil { - return fmt.Errorf("failed to get home directory: %v", err) + return fmt.Errorf("failed to get home directory: %w", err) } zcliPath := fmt.Sprintf("%s/.local/bin/zcli", homeDir) @@ -49,7 +48,7 @@ func rootCmd() *cmdBuilder.Cmd { cmd.Stdout = cmdData.Stdout.GetWriter() cmd.Stdin = os.Stdin if err := cmd.Run(); err != nil { - return fmt.Errorf("failed to execute 'zcli update': %v", err) + return fmt.Errorf("failed to execute 'zcli update': %w", err) } cmdData.Stdout.PrintLines( diff --git a/src/cmd/update.go b/src/cmd/update.go index 77ce1c54..18941a13 100644 --- a/src/cmd/update.go +++ b/src/cmd/update.go @@ -36,7 +36,10 @@ func updateCmd() *cmdBuilder.Cmd { fmt.Println("There is a new version available:", latestVersion.TagName) fmt.Println("Do you want to update? (y/n)") var input string - fmt.Scanln(&input) + if _, err := fmt.Scanln(&input); err != nil { + fmt.Println("Failed to read input:", err) + return err + } if input == "y" { target := determineTargetArchitecture() @@ -58,7 +61,7 @@ func updateCmd() *cmdBuilder.Cmd { } type GitHubRelease struct { - TagName string `json:"tag_name"` + TagName string `json:"tagName"` Body string `json:"body"` } @@ -73,7 +76,7 @@ func getLatestGitHubRelease(ctx context.Context) (GitHubRelease, error) { Timeout: 4 * time.Second, } - req, err := http.NewRequestWithContext(ctx, "GET", apiURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, nil) if err != nil { return GitHubRelease{}, err }