Fixed --help and --version when no config file found.
[src/xds/xds-gdb.git] / main.go
diff --git a/main.go b/main.go
index 01b46c9..1c2e6d8 100644 (file)
--- a/main.go
+++ b/main.go
@@ -190,8 +190,12 @@ endloop:
        // Source config env file
        // (we cannot use confFile var because env variables setting is just after)
        envMap, confFile, err := loadConfigEnvFile(os.Getenv("XDS_CONFIG"), gdbCmdFile)
-       if err != nil {
-               exitError(syscall.ENOENT, err.Error())
+
+       // Only rise an error when args is not set (IOW when --help or --version is not set)
+       if len(args) == 1 {
+               if err != nil {
+                       exitError(syscall.ENOENT, err.Error())
+               }
        }
 
        // Managed env vars and create help
@@ -487,7 +491,7 @@ func loadConfigEnvFile(confFile, gdbCmdFile string) (map[string]string, string,
                                path.Join(curDir, "../../target"),
                                path.Join(u.HomeDir, ".xds"),
                        } {
-                               confFile := path.Join(d, xdsEnvFile)
+                               confFile = path.Join(d, xdsEnvFile)
                                logEarly("Search config in %s", confFile)
                                if common.Exists(confFile) {
                                        break