Fix printing full executable path in error messages on Windows

This commit is contained in:
2024-07-09 15:20:36 -04:00
parent 7e935c2875
commit b3f4b2b000
5 changed files with 23 additions and 4 deletions
+9
View File
@@ -0,0 +1,9 @@
//go:build !windows
package sync
import (
"os"
)
var vanityEXE = os.Args[0]
+10
View File
@@ -0,0 +1,10 @@
//go:build windows
package sync
import (
"os"
"strings"
)
var vanityEXE = os.Args[0][strings.LastIndex(os.Args[0], "\\")+1:]
+2 -2
View File
@@ -26,7 +26,7 @@ func getSSHClient(manualSync bool) (*ssh.Client, string, bool) {
var sshUserConfig []string
var missingValueError string
if manualSync {
missingValueError = "SSH settings not configured - run \"" + os.Args[0] + " init\" to configure"
missingValueError = "SSH settings not configured - run \"" + vanityEXE + " init\" to configure"
} else {
missingValueError = "0"
}
@@ -135,7 +135,7 @@ func getRemoteDataFromClient(manualSync bool) (map[string]int64, []string, []str
clientDeviceID, _ := os.ReadDir(backend.ConfigDir + backend.PathSeparator + "devices")
if len(clientDeviceID) == 0 {
if manualSync {
fmt.Println(backend.AnsiError + "Sync failed - No device ID found; run \"" + os.Args[0] + " init\" to generate a device ID" + backend.AnsiReset)
fmt.Println(backend.AnsiError + "Sync failed - No device ID found; run \"" + vanityEXE + " init\" to generate a device ID" + backend.AnsiReset)
os.Exit(1)
} else {
backend.Exit(0) // exit silently if the sync job was called automatically, as the user may just be in offline mode
+1 -1
View File
@@ -24,7 +24,7 @@ func WalkEntryDir() ([]string, []string) {
// check for errors encountered while walking directory
if err != nil {
if os.IsNotExist(err) {
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+os.Args[0], "init"+"\" to create it"+backend.AnsiReset)
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+vanityEXE, "init"+"\" to create it"+backend.AnsiReset)
} else {
// otherwise, print the source of the error
fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)
+1 -1
View File
@@ -25,7 +25,7 @@ func WalkEntryDir() ([]string, []string) {
// check for errors encountered while walking directory
if err != nil {
if os.IsNotExist(err) {
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+os.Args[0], "init"+"\" to create it"+backend.AnsiReset)
fmt.Println(backend.AnsiError+"The entry directory does not exist - run \""+vanityEXE, "init"+"\" to create it"+backend.AnsiReset)
} else {
// otherwise, print the source of the error
fmt.Println(backend.AnsiError + "An unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)