From 77162ada68a91c16d03e4454a7ece18553fe1cec Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 24 May 2013 17:48:30 -0400 Subject: [PATCH] auto-detect package path of gpm, so binary can be put in any path that is in /c/Users/Unknown/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Program Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (x86)/Windows Live/Shared:/c/Program Files/Intel/WiFi/bin/:/c/Program Files/Common Files/Intel/WirelessCommon/:/c/Program Files/Microsoft/Web Platform Installer/:/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0/:/c/Program Files (x86)/Windows Kits/8.0/Windows Performance Toolkit/:/c/Program Files/Microsoft SQL Server/110/Tools/Binn/:/d/TortoiseHg/:/d/Qt/Qt5.0.1/5.0.1/msvc2010/bin:/d/Java/jdk1.7.0_17/bin:/d/Java/jdk1.7.0_17/jre/bin:/d/MinGW64/bin:/d/MinGW/bin:/c/Program Files/MySQL/MySQL Server 5.1/bin:/d/go/bin:/cmd:/bin:/e/Go/Development/src/github.com/GPMGo/gpm --- README.md | 2 -- conf/gpm.toml | 2 +- gpm.go | 13 +++++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e8c915a6c..1871acda8 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,6 @@ This application still in experiment, any change could happen, but it doesn't af ### v0.2.* -- Add feature auto-catch if run under GOPATH/bin. - ### Future - Command `check` add feature to update or generate gopack.json. diff --git a/conf/gpm.toml b/conf/gpm.toml index 84584dc5d..5555f5cc3 100644 --- a/conf/gpm.toml +++ b/conf/gpm.toml @@ -1,7 +1,7 @@ # This is a configuration file for gpm with toml format. title = "gpm(Go Package Manager)" -version = "v0.2.0 Build 0524" +version = "v0.2.1 Build 0524" user_language = "en-US" #user_language = "zh-CN" auto_backup = true diff --git a/gpm.go b/gpm.go index 69bf36a08..9bbdbd3ab 100644 --- a/gpm.go +++ b/gpm.go @@ -114,16 +114,25 @@ func getAppPath() bool { // Look up executable in PATH variable. appPath, _ = exec.LookPath(path.Base(os.Args[0])) // Check if run under $GOPATH/bin + if !utils.IsExist(appPath + "conf/") { + paths := utils.GetGOPATH() + for _, p := range paths { + if utils.IsExist(p + "/src/github.com/GPMGo/gpm/") { + appPath = p + "/src/github.com/GPMGo/gpm/" + break + } + } + } if len(appPath) == 0 { fmt.Printf("ERROR: getAppPath -> Unable to indicate current execute path.\n") return false } - appPath += "/" + appPath = filepath.Dir(appPath) + "/" if runtime.GOOS == "windows" { // Replace all '\' to '/'. - appPath = strings.Replace(filepath.Dir(appPath), "\\", "/", -1) + appPath = strings.Replace(appPath, "\\", "/", -1) } doc.SetAppConfig(appPath, config.AutoBackup)