()
| 37 | } |
| 38 | |
| 39 | func confirmAndSelfUpdate() { |
| 40 | latest, found, err := selfupdate.DetectLatest(info) |
| 41 | if err != nil { |
| 42 | log.Infoln("Error occurred while detecting version:", err) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | v := semver.MustParse(version) |
| 47 | if !found || latest.Version.LTE(v) { |
| 48 | log.Infof("Current version is the latest version %s", version) |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | fmt.Print("Do you want to update to latest version ", latest.Version, "? (y/n): ") |
| 53 | input, err := bufio.NewReader(os.Stdin).ReadString('\n') |
| 54 | // 如果input 存在\r或者\n,则去掉 |
| 55 | if stringsutil.HasSuffixAny(input, "\r\n", "\n", "\r") { |
| 56 | input = stringsutil.TrimSuffixAny(input, "\r\n", "\n", "\r") |
| 57 | } |
| 58 | if err != nil || (input != "y" && input != "n" && input != "Y" && input != "N") { |
| 59 | log.Println("Invalid input") |
| 60 | return |
| 61 | } |
| 62 | if input == "n" { |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | exe, err := os.Executable() |
| 67 | if err != nil { |
| 68 | log.Println("Could not locate executable path") |
| 69 | return |
| 70 | } |
| 71 | if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil { |
| 72 | log.Println("Error occurred while updating binary:", err) |
| 73 | return |
| 74 | } |
| 75 | log.Println("Successfully updated to version", latest.Version) |
| 76 | } |
no outgoing calls
no test coverage detected