From 60ed1d3cc809c773891d4fa2e8d40e27d167ad0d Mon Sep 17 00:00:00 2001 From: Marwan Hawari Date: Sat, 5 Mar 2022 10:37:34 -0800 Subject: [PATCH 1/4] add prompt for renaming binaries --- lib/ui.go | 18 ++++++++++++++++++ lib/util.go | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/ui.go b/lib/ui.go index eedfdeb..a74ebea 100644 --- a/lib/ui.go +++ b/lib/ui.go @@ -55,3 +55,21 @@ func WarningPromptConfirm(message string) (bool, error) { return result, nil } + +// WarningPromptInput launches the input UI with a warning styling +func warningPromptInput(message string, defaultInput string) (string, error) { + result := "" + prompt := &survey.Input{ + Message: message, + Default: defaultInput, + } + err := survey.AskOne(prompt, &result, survey.WithIcons(func(icons *survey.IconSet) { + icons.Question.Text = "!" + icons.Question.Format = "yellow+hb" + })) + if err != nil { + return "", ExitUserSelectionError{Err: err} + } + + return result, nil +} diff --git a/lib/util.go b/lib/util.go index 270ed2f..d085b84 100644 --- a/lib/util.go +++ b/lib/util.go @@ -5,7 +5,6 @@ import ( "io" "net/http" "os" - "path" "path/filepath" "regexp" "runtime" @@ -41,7 +40,7 @@ func CatchAndExit(err error) { if err != nil { fmt.Println(err) stewPath, _ := GetStewPath() - stewTmpPath := path.Join(stewPath, "tmp") + stewTmpPath := filepath.Join(stewPath, "tmp") err = os.RemoveAll(stewTmpPath) if err != nil { fmt.Println(err) @@ -195,6 +194,10 @@ func getBinary(filePaths []string, repo string) (string, string, error) { return "", "", err } binaryName = filepath.Base(binaryFile) + binaryName, err = renameBinary(binaryName) + if err != nil { + return "", "", nil + } } } @@ -276,7 +279,7 @@ func parseGithubInput(cliInput string) (CLIInput, error) { } func parseURLInput(cliInput string) (CLIInput, error) { - return CLIInput{IsGithubInput: false, Asset: path.Base(cliInput), DownloadURL: cliInput}, nil + return CLIInput{IsGithubInput: false, Asset: filepath.Base(cliInput), DownloadURL: cliInput}, nil } // Contains checks if a string slice contains a given target @@ -298,14 +301,26 @@ func getArch() string { } func extractBinary(downloadedFilePath, tmpExtractionPath string) error { - var err error isArchive := isArchiveFile(downloadedFilePath) if isArchive { - err = archiver.Unarchive(downloadedFilePath, tmpExtractionPath) + err := archiver.Unarchive(downloadedFilePath, tmpExtractionPath) + if err != nil { + return err + } + } else { - err = copyFile(downloadedFilePath, path.Join(tmpExtractionPath, filepath.Base(downloadedFilePath))) + originalBinaryName := filepath.Base(downloadedFilePath) + + renamedBinaryName, err := renameBinary(originalBinaryName) + if err != nil { + return err + } + err = copyFile(downloadedFilePath, filepath.Join(tmpExtractionPath, renamedBinaryName)) + if err != nil { + return err + } } - return err + return nil } // InstallBinary will extract the binary and copy it to the ~/.stew/bin path @@ -332,7 +347,7 @@ func InstallBinary(downloadedFilePath string, repo string, systemInfo SystemInfo // Check if the binary already exists for index, pkg := range lockFile.Packages { - previousAssetPath := path.Join(assetDownloadPath, pkg.Asset) + previousAssetPath := filepath.Join(assetDownloadPath, pkg.Asset) newAssetPath := downloadedFilePath var overwrite bool if pkg.Binary == binaryName { @@ -375,7 +390,7 @@ func InstallBinary(downloadedFilePath string, repo string, systemInfo SystemInfo } } - err = copyFile(binaryFile, path.Join(binaryInstallPath, binaryName)) + err = copyFile(binaryFile, filepath.Join(binaryInstallPath, binaryName)) if err != nil { return "", err } @@ -387,3 +402,12 @@ func InstallBinary(downloadedFilePath string, repo string, systemInfo SystemInfo return binaryName, nil } + +// renameBinary takes in the original name of the binary and will return the new name of the binary. +func renameBinary(originalBinaryName string) (string, error) { + renamedBinaryName, err := warningPromptInput("Rename the binary?", originalBinaryName) + if err != nil { + return "", err + } + return renamedBinaryName, nil +} From 1c8626916247e02e83a2b9df5f39b607cd2fb09a Mon Sep 17 00:00:00 2001 From: Marwan Hawari Date: Sat, 5 Mar 2022 11:28:46 -0800 Subject: [PATCH 2/4] add 'rename' subcommand --- cmd/rename.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/util.go | 8 ++++---- main.go | 9 +++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 cmd/rename.go diff --git a/cmd/rename.go b/cmd/rename.go new file mode 100644 index 0000000..9505ea6 --- /dev/null +++ b/cmd/rename.go @@ -0,0 +1,56 @@ +package cmd + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/marwanhawari/stew/constants" + stew "github.com/marwanhawari/stew/lib" +) + +// Rename is executed when you run `stew rename` +func Rename(cliInput string) { + + err := stew.ValidateCLIInput(cliInput) + stew.CatchAndExit(err) + + stewPath, err := stew.GetStewPath() + stew.CatchAndExit(err) + systemInfo := stew.NewSystemInfo(stewPath) + + userOS := systemInfo.Os + userArch := systemInfo.Arch + stewBinPath := systemInfo.StewBinPath + stewLockFilePath := systemInfo.StewLockFilePath + + lockFile, err := stew.NewLockFile(stewLockFilePath, userOS, userArch) + stew.CatchAndExit(err) + + if len(lockFile.Packages) == 0 { + stew.CatchAndExit(stew.NoBinariesInstalledError{}) + } + + var binaryFound bool + var renamedBinaryName string + for index, pkg := range lockFile.Packages { + if pkg.Binary == cliInput { + renamedBinaryName, err = stew.PromptRenameBinary(cliInput) + stew.CatchAndExit(err) + err = os.Rename(filepath.Join(stewBinPath, cliInput), filepath.Join(stewBinPath, renamedBinaryName)) + stew.CatchAndExit(err) + + lockFile.Packages[index].Binary = renamedBinaryName + binaryFound = true + break + } + } + if !binaryFound { + stew.CatchAndExit(stew.BinaryNotInstalledError{Binary: cliInput}) + } + + err = stew.WriteLockFileJSON(lockFile, stewLockFilePath) + stew.CatchAndExit(err) + + fmt.Printf("✨ Successfully renamed the %v binary to %v\n", constants.GreenColor(cliInput), constants.GreenColor(renamedBinaryName)) +} diff --git a/lib/util.go b/lib/util.go index d085b84..a04e785 100644 --- a/lib/util.go +++ b/lib/util.go @@ -194,7 +194,7 @@ func getBinary(filePaths []string, repo string) (string, string, error) { return "", "", err } binaryName = filepath.Base(binaryFile) - binaryName, err = renameBinary(binaryName) + binaryName, err = PromptRenameBinary(binaryName) if err != nil { return "", "", nil } @@ -311,7 +311,7 @@ func extractBinary(downloadedFilePath, tmpExtractionPath string) error { } else { originalBinaryName := filepath.Base(downloadedFilePath) - renamedBinaryName, err := renameBinary(originalBinaryName) + renamedBinaryName, err := PromptRenameBinary(originalBinaryName) if err != nil { return err } @@ -403,8 +403,8 @@ func InstallBinary(downloadedFilePath string, repo string, systemInfo SystemInfo return binaryName, nil } -// renameBinary takes in the original name of the binary and will return the new name of the binary. -func renameBinary(originalBinaryName string) (string, error) { +// PromptRenameBinary takes in the original name of the binary and will return the new name of the binary. +func PromptRenameBinary(originalBinaryName string) (string, error) { renamedBinaryName, err := warningPromptInput("Rename the binary?", originalBinaryName) if err != nil { return "", err diff --git a/main.go b/main.go index 62eb54d..d83365f 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,15 @@ func main() { return nil }, }, + { + Name: "rename", + Usage: "Rename an installed binary using a prompt UI. [Ex: stew rename fzf]", + Aliases: []string{"re"}, + Action: func(c *cli.Context) error { + cmd.Rename(c.Args().First()) + return nil + }, + }, { Name: "list", Usage: "List installed binaries [Ex: stew list]", From 62e9c912d2ae4c2d6beff9e5bced38d6a3fe0b0e Mon Sep 17 00:00:00 2001 From: Marwan Hawari Date: Sat, 5 Mar 2022 11:31:43 -0800 Subject: [PATCH 3/4] path lib to filepath lib --- cmd/browse.go | 4 ++-- cmd/install.go | 4 ++-- cmd/upgrade.go | 4 ++-- lib/stewfile.go | 14 +++++++------- lib/stewfile_test.go | 30 +++++++++++++++--------------- lib/util_test.go | 44 ++++++++++++++++++++++---------------------- 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/cmd/browse.go b/cmd/browse.go index 0dd99be..f394f4c 100644 --- a/cmd/browse.go +++ b/cmd/browse.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" "os" - "path" + "path/filepath" "github.com/marwanhawari/stew/constants" stew "github.com/marwanhawari/stew/lib" @@ -57,7 +57,7 @@ func Browse(cliInput string) { assetIndex, _ := stew.Contains(releaseAssets, asset) downloadURL := githubProject.Releases[tagIndex].Assets[assetIndex].DownloadURL - downloadPath := path.Join(stewPkgPath, asset) + downloadPath := filepath.Join(stewPkgPath, asset) downloadPathExists, err := stew.PathExists(downloadPath) stew.CatchAndExit(err) diff --git a/cmd/install.go b/cmd/install.go index a5b309a..7edd4fa 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" "os" - "path" + "path/filepath" "strings" "github.com/marwanhawari/stew/constants" @@ -102,7 +102,7 @@ func Install(cliInputs []string) { fmt.Println(constants.GreenColor(asset)) } - downloadPath := path.Join(stewPkgPath, asset) + downloadPath := filepath.Join(stewPkgPath, asset) downloadPathExists, err := stew.PathExists(downloadPath) stew.CatchAndExit(err) if downloadPathExists { diff --git a/cmd/upgrade.go b/cmd/upgrade.go index c1ac223..08a85fc 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" "os" - "path" + "path/filepath" "github.com/marwanhawari/stew/constants" stew "github.com/marwanhawari/stew/lib" @@ -89,7 +89,7 @@ func Upgrade(cliFlag bool, binaryName string) { downloadURL := githubProject.Releases[tagIndex].Assets[assetIndex].DownloadURL - downloadPath := path.Join(stewPkgPath, asset) + downloadPath := filepath.Join(stewPkgPath, asset) downloadPathExists, err := stew.PathExists(downloadPath) stew.CatchAndExit(err) if downloadPathExists { diff --git a/lib/stewfile.go b/lib/stewfile.go index b22bdd6..f8def87 100644 --- a/lib/stewfile.go +++ b/lib/stewfile.go @@ -6,7 +6,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "github.com/marwanhawari/stew/constants" ) @@ -131,10 +131,10 @@ type SystemInfo struct { func NewSystemInfo(stewPath string) SystemInfo { var systemInfo SystemInfo systemInfo.StewPath = stewPath - systemInfo.StewBinPath = path.Join(stewPath, "bin") - systemInfo.StewPkgPath = path.Join(stewPath, "pkg") - systemInfo.StewLockFilePath = path.Join(stewPath, "Stewfile.lock.json") - systemInfo.StewTmpPath = path.Join(stewPath, "tmp") + systemInfo.StewBinPath = filepath.Join(stewPath, "bin") + systemInfo.StewPkgPath = filepath.Join(stewPath, "pkg") + systemInfo.StewLockFilePath = filepath.Join(stewPath, "Stewfile.lock.json") + systemInfo.StewTmpPath = filepath.Join(stewPath, "tmp") systemInfo.Os = getOS() systemInfo.Arch = getArch() @@ -143,8 +143,8 @@ func NewSystemInfo(stewPath string) SystemInfo { // DeleteAssetAndBinary will delete the asset from the ~/.stew/pkg path and delete the binary from the ~/.stew/bin path func DeleteAssetAndBinary(stewPkgPath, stewBinPath, asset, binary string) error { - assetPath := path.Join(stewPkgPath, asset) - binPath := path.Join(stewBinPath, binary) + assetPath := filepath.Join(stewPkgPath, asset) + binPath := filepath.Join(stewBinPath, binary) err := os.RemoveAll(assetPath) if err != nil { return err diff --git a/lib/stewfile_test.go b/lib/stewfile_test.go index 3d1c19a..3934af0 100644 --- a/lib/stewfile_test.go +++ b/lib/stewfile_test.go @@ -3,7 +3,7 @@ package stew import ( "io/ioutil" "os" - "path" + "path/filepath" "reflect" "runtime" "testing" @@ -69,7 +69,7 @@ func Test_readLockFileJSON(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") WriteLockFileJSON(testLockfile, lockFilePath) got, err := readLockFileJSON(lockFilePath) @@ -97,7 +97,7 @@ func TestWriteLockFileJSON(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") if err := WriteLockFileJSON(testLockfile, lockFilePath); (err != nil) != tt.wantErr { t.Errorf("WriteLockFileJSON() error = %v, wantErr %v", err, tt.wantErr) @@ -201,7 +201,7 @@ func TestReadStewfileContents(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testStewfilePath := path.Join(tempDir, "Stewfile") + testStewfilePath := filepath.Join(tempDir, "Stewfile") ioutil.WriteFile(testStewfilePath, []byte(testStewfileContents), 0644) got, err := ReadStewfileContents(testStewfilePath) @@ -241,7 +241,7 @@ func TestNewLockFile(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") WriteLockFileJSON(testLockfile, lockFilePath) got, err := NewLockFile(lockFilePath, tt.args.userOS, tt.args.userArch) @@ -279,7 +279,7 @@ func TestNewLockFileDoesntExist(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") got, err := NewLockFile(lockFilePath, tt.args.userOS, tt.args.userArch) if (err != nil) != tt.wantErr { @@ -309,10 +309,10 @@ func TestNewSystemInfo(t *testing.T) { Os: runtime.GOOS, Arch: runtime.GOARCH, StewPath: tempDir, - StewBinPath: path.Join(tempDir, "bin"), - StewPkgPath: path.Join(tempDir, "pkg"), - StewLockFilePath: path.Join(tempDir, "Stewfile.lock.json"), - StewTmpPath: path.Join(tempDir, "tmp"), + StewBinPath: filepath.Join(tempDir, "bin"), + StewPkgPath: filepath.Join(tempDir, "pkg"), + StewLockFilePath: filepath.Join(tempDir, "Stewfile.lock.json"), + StewTmpPath: filepath.Join(tempDir, "tmp"), } got := NewSystemInfo(tempDir) @@ -336,10 +336,10 @@ func TestDeleteAssetAndBinary(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - os.MkdirAll(path.Join(tempDir, "pkg"), 0755) - testStewAssetPath := path.Join(tempDir, "pkg", "testAsset.tar.gz") - os.MkdirAll(path.Join(tempDir, "bin"), 0755) - testStewBinaryPath := path.Join(tempDir, "bin", "testBinary") + os.MkdirAll(filepath.Join(tempDir, "pkg"), 0755) + testStewAssetPath := filepath.Join(tempDir, "pkg", "testAsset.tar.gz") + os.MkdirAll(filepath.Join(tempDir, "bin"), 0755) + testStewBinaryPath := filepath.Join(tempDir, "bin", "testBinary") ioutil.WriteFile(testStewAssetPath, []byte("This is a test asset"), 0644) ioutil.WriteFile(testStewBinaryPath, []byte("This is a test binary"), 0644) @@ -351,7 +351,7 @@ func TestDeleteAssetAndBinary(t *testing.T) { t.Errorf("Either the asset or the binary does not exist yet") } - if err := DeleteAssetAndBinary(path.Dir(testStewAssetPath), path.Dir(testStewBinaryPath), path.Base(testStewAssetPath), path.Base(testStewBinaryPath)); (err != nil) != tt.wantErr { + if err := DeleteAssetAndBinary(filepath.Dir(testStewAssetPath), filepath.Dir(testStewBinaryPath), filepath.Base(testStewAssetPath), filepath.Base(testStewBinaryPath)); (err != nil) != tt.wantErr { t.Errorf("DeleteAssetAndBinary() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/lib/util_test.go b/lib/util_test.go index ab2ccc5..9157589 100644 --- a/lib/util_test.go +++ b/lib/util_test.go @@ -3,7 +3,7 @@ package stew import ( "io/ioutil" "os" - "path" + "path/filepath" "reflect" "runtime" "testing" @@ -72,7 +72,7 @@ func Test_isExecutableFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testExecutableFilePath := path.Join(tempDir, tt.args.filePath) + testExecutableFilePath := filepath.Join(tempDir, tt.args.filePath) if tt.want { ioutil.WriteFile(testExecutableFilePath, []byte("An executable file"), 0755) } else { @@ -121,7 +121,7 @@ func TestPathExists(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testFilePath := path.Join(tempDir, tt.args.path) + testFilePath := filepath.Join(tempDir, tt.args.path) if tt.want { ioutil.WriteFile(testFilePath, []byte("A test file"), 0644) } @@ -151,7 +151,7 @@ func TestGetStewPath(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { homeDir, _ := os.UserHomeDir() - testStewPath := path.Join(homeDir, ".stew") + testStewPath := filepath.Join(homeDir, ".stew") stewPathExists, _ := PathExists(testStewPath) if !stewPathExists { os.MkdirAll(testStewPath, 0755) @@ -200,7 +200,7 @@ func TestDownloadFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testDownloadPath := path.Join(tempDir, path.Base(tt.args.url)) + testDownloadPath := filepath.Join(tempDir, filepath.Base(tt.args.url)) if err := DownloadFile(testDownloadPath, tt.args.url); (err != nil) != tt.wantErr { t.Errorf("DownloadFile() error = %v, wantErr %v", err, tt.wantErr) return @@ -235,8 +235,8 @@ func Test_copyFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - srcFilePath := path.Join(tempDir, tt.args.srcFile) - destFilePath := path.Join(tempDir, tt.args.destFile) + srcFilePath := filepath.Join(tempDir, tt.args.srcFile) + destFilePath := filepath.Join(tempDir, tt.args.destFile) ioutil.WriteFile(srcFilePath, []byte("A test file"), 0644) @@ -280,11 +280,11 @@ func Test_walkDir(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - ioutil.WriteFile(path.Join(tempDir, "testFile.txt"), []byte("A test file"), 0644) - os.MkdirAll(path.Join(tempDir, "bin"), 0755) - ioutil.WriteFile(path.Join(tempDir, "bin", "binDirTestFile.txt"), []byte("Another test file"), 0644) + ioutil.WriteFile(filepath.Join(tempDir, "testFile.txt"), []byte("A test file"), 0644) + os.MkdirAll(filepath.Join(tempDir, "bin"), 0755) + ioutil.WriteFile(filepath.Join(tempDir, "bin", "binDirTestFile.txt"), []byte("Another test file"), 0644) - want := []string{path.Join(tempDir, "bin", "binDirTestFile.txt"), path.Join(tempDir, "testFile.txt")} + want := []string{filepath.Join(tempDir, "bin", "binDirTestFile.txt"), filepath.Join(tempDir, "testFile.txt")} got, err := walkDir(tempDir) if (err != nil) != tt.wantErr { @@ -337,15 +337,15 @@ func Test_getBinary(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testBinaryFilePath := path.Join(tempDir, tt.binaryName) + testBinaryFilePath := filepath.Join(tempDir, tt.binaryName) ioutil.WriteFile(testBinaryFilePath, []byte("An executable file"), 0755) - testNonBinaryFilePath := path.Join(tempDir, "testNonBinary") + testNonBinaryFilePath := filepath.Join(tempDir, "testNonBinary") ioutil.WriteFile(testNonBinaryFilePath, []byte("Not an executable file"), 0644) testFilePaths := []string{testBinaryFilePath, testNonBinaryFilePath} - wantBinaryFile := path.Join(tempDir, tt.binaryName) - wantBinaryName := path.Base(wantBinaryFile) + wantBinaryFile := filepath.Join(tempDir, tt.binaryName) + wantBinaryName := filepath.Base(wantBinaryFile) got, got1, err := getBinary(testFilePaths, tt.args.repo) if (err != nil) != tt.wantErr { @@ -385,7 +385,7 @@ func Test_getBinaryError(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testNonBinaryFilePath := path.Join(tempDir, "testNonBinary") + testNonBinaryFilePath := filepath.Join(tempDir, "testNonBinary") ioutil.WriteFile(testNonBinaryFilePath, []byte("Not an executable file"), 0644) testFilePaths := []string{testNonBinaryFilePath} @@ -702,8 +702,8 @@ func Test_extractBinary(t *testing.T) { { name: "test1", args: args{ - downloadedFilePath: path.Join(t.TempDir(), "ppath-v0.0.3-darwin-arm64.tar.gz"), - tmpExtractionPath: path.Join(t.TempDir(), "tmp"), + downloadedFilePath: filepath.Join(t.TempDir(), "ppath-v0.0.3-darwin-arm64.tar.gz"), + tmpExtractionPath: filepath.Join(t.TempDir(), "tmp"), }, url: "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz", wantErr: false, @@ -735,7 +735,7 @@ func TestInstallBinary(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - stewPath := path.Join(tempDir, ".stew") + stewPath := filepath.Join(tempDir, ".stew") repo := "ppath" systemInfo := NewSystemInfo(stewPath) @@ -759,7 +759,7 @@ func TestInstallBinary(t *testing.T) { }, } - downloadedFilePath := path.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") + downloadedFilePath := filepath.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") err := DownloadFile(downloadedFilePath, "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz") if err != nil { @@ -794,7 +794,7 @@ func TestInstallBinary_Fail(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - stewPath := path.Join(tempDir, ".stew") + stewPath := filepath.Join(tempDir, ".stew") repo := "ppath" systemInfo := NewSystemInfo(stewPath) @@ -818,7 +818,7 @@ func TestInstallBinary_Fail(t *testing.T) { }, } - downloadedFilePath := path.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") + downloadedFilePath := filepath.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") err := DownloadFile(downloadedFilePath, "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz") if err != nil { From d91fd27359d872698986b0dbb9532a9a455a44e9 Mon Sep 17 00:00:00 2001 From: Marwan Hawari <59078997+marwanhawari@users.noreply.github.com> Date: Sat, 5 Mar 2022 11:44:13 -0800 Subject: [PATCH 4/4] fix documentation comment --- lib/ui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui.go b/lib/ui.go index a74ebea..168d35c 100644 --- a/lib/ui.go +++ b/lib/ui.go @@ -56,7 +56,7 @@ func WarningPromptConfirm(message string) (bool, error) { return result, nil } -// WarningPromptInput launches the input UI with a warning styling +// warningPromptInput launches the input UI with a warning styling func warningPromptInput(message string, defaultInput string) (string, error) { result := "" prompt := &survey.Input{