fix path bug for windows

This commit is contained in:
STARAI\Star 2024-09-08 21:06:23 +08:00
parent dea12f178a
commit 874e63e4f5

24
main.go
View File

@ -9,7 +9,6 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
@ -95,7 +94,7 @@ var cachePath = "c:\\.ag\\cache"
func init() {
hc.SetGlobalHeader("Content-Type", "application/json")
if homePath, err := os.UserHomeDir(); err == nil {
cachePath = path.Join(homePath, ".ag", "cache")
cachePath = filepath.Join(homePath, ".ag", "cache")
}
}
@ -205,15 +204,15 @@ func checkProjectPath() string {
// }
// return args[0]
//} else {
if len(u.ReadDirN(".")) != 0 {
fmt.Println(u.BRed("current path is not empty"))
if u.FileExists("go.mod") {
fmt.Println(u.BRed("go.mod exists"))
return ""
}
if pathname, err := os.Getwd(); err != nil {
fmt.Println(u.BRed("getwd error: " + err.Error()))
return ""
} else {
return path.Base(pathname)
return filepath.Base(pathname)
}
//}
}
@ -261,14 +260,14 @@ type Tag struct {
func fetchRepo(name string) (repoPath string) {
apiUrl, owner, repo := parseRepo(name)
tagsUrl := apiUrl + path.Join("repos", owner, repo, "tags")
tagsUrl := apiUrl + filepath.Join("repos", owner, repo, "tags")
tags := make([]Tag, 0)
fmt.Println("try to fetch tags", tagsUrl)
r := hc.Get(tagsUrl)
if r.Error == nil {
r.To(&tags)
} else if apiUrl != "https://api.github.com/" {
tagsUrl = "https://api.github.com/" + path.Join("repos", owner, repo, "tags")
tagsUrl = "https://api.github.com/" + filepath.Join("repos", owner, repo, "tags")
fmt.Println("try to fetch tags", tagsUrl)
r = hc.Get(tagsUrl)
if r.Error == nil {
@ -721,13 +720,14 @@ func main() {
if len(os.Args) > 2 {
cmd2 += " " + os.Args[2]
}
for _, cmdInfo := range commands {
if cmd1 == cmdInfo.Name || cmd1 == cmdInfo.ShortName {
cmdInfo.Func(os.Args[2:])
return
} else if cmd2 == cmdInfo.Name {
for i := len(commands) - 1; i >= 0; i-- {
cmdInfo := commands[i]
if cmd2 == cmdInfo.Name || cmd2 == cmdInfo.ShortName {
cmdInfo.Func(os.Args[3:])
return
} else if cmd1 == cmdInfo.Name || cmd1 == cmdInfo.ShortName {
cmdInfo.Func(os.Args[2:])
return
}
}
}