refactor: handling functions for cross-platform compatibility (#166)

- Change the `rmcmd` and `mkdircmd` functions to accept an OS parameter
- Remove `command_windows.go` file
- Modify `removeDestFile` and `Exec` functions to use the OS parameter
- Add OS detection logic to `removeAllDestFile` and `Exec` functions
- Modify `TestRemoveDestFile` function to use the OS parameter

fix https://github.com/appleboy/drone-scp/pull/119
This commit is contained in:
Bo-Yi Wu
2023-04-09 08:14:05 +08:00
committed by GitHub
parent 8b578d1df8
commit 244b0a9e58
4 changed files with 59 additions and 28 deletions
+17 -7
View File
@@ -1,12 +1,22 @@
//go:build !windows
// +build !windows
package main
func rmcmd(target string) string {
return "rm -rf " + target
func rmcmd(os, target string) string {
switch os {
case "windows":
return "DEL /F /S " + target
case "unix":
return "rm -rf " + target
}
return ""
}
func mkdircmd(target string) string {
return "mkdir -p " + target
func mkdircmd(os, target string) string {
switch os {
case "windows":
return "if not exist " + target + " mkdir " + target
case "unix":
return "mkdir -p " + target
}
return ""
}