From 1989551e90b348aad945868cc960088d69fac9b1 Mon Sep 17 00:00:00 2001 From: rluisr Date: Fri, 20 Oct 2023 20:36:14 +0900 Subject: [PATCH] feat: Update download and installation process for Copilot --- .gitignore | 2 ++ main.go | 21 ++++++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index e69de29..c9054f5 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +cenv +.copilot-version \ No newline at end of file diff --git a/main.go b/main.go index 82949d2..a68c2b6 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,7 @@ func readVersionFile() (string, error) { } func downloadAndInstallCopilot(version string, local bool) error { - url := fmt.Sprintf("https://github.com/aws/copilot-cli/releases/download/v%s/copilot-%s-%s", version, runtime.GOOS, runtime.GOARCH) + url := fmt.Sprintf("https://github.com/aws/copilot-cli/releases/download/v%s/copilot-%s-%s-v%s", version, runtime.GOOS, runtime.GOARCH, version) resp, err := http.Get(url) if err != nil { @@ -57,12 +57,12 @@ func downloadAndInstallCopilot(version string, local bool) error { if err != nil { return err } - installPath = fmt.Sprintf("%s/copilot", currentDir) + installPath = fmt.Sprintf("%s/copilot-%s", currentDir, runtime.GOOS) } else { - installPath = "/usr/local/bin/copilot" + installPath = fmt.Sprintf("/usr/local/bin/copilot-%s", runtime.GOOS) } - out, err := os.Create(installPath) + out, err := os.OpenFile(installPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755) if err != nil { return err } @@ -73,17 +73,7 @@ func downloadAndInstallCopilot(version string, local bool) error { return err } - err = os.Chmod(installPath, 0755) - if err != nil { - return err - } - - var cmd *exec.Cmd - if local { - cmd = exec.Command("./copilot", "-v") - } else { - cmd = exec.Command("copilot", "-v") - } + cmd := exec.Command(installPath, "-v") output, err := cmd.CombinedOutput() if err != nil { @@ -91,6 +81,7 @@ func downloadAndInstallCopilot(version string, local bool) error { } fmt.Println(string(output)) + fmt.Printf("Copilot installed successfully to %s\n", installPath) return nil }