File tree Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -198,11 +198,50 @@ func initConfig() {
198
198
}
199
199
200
200
func getProjectDir (dir string ) (string , error ) {
201
+
202
+ var projDir string
203
+
201
204
if dir != "" {
202
- if filepath .IsAbs (dir ) {
203
- return dir , nil
205
+ // Get Absolute Path
206
+ absPath , err := getAbsPath (dir )
207
+ if err != nil {
208
+ return "" , err
204
209
}
205
- return filepath .Abs (dir )
210
+ projDir = absPath
211
+
212
+ } else {
213
+ // Get Current Working Dir
214
+ cwd , err := os .Getwd ()
215
+ if err != nil {
216
+ return "" , err
217
+ }
218
+ projDir = cwd
219
+ }
220
+ // Let us evaluate the symlinks
221
+ realPath , err := filepath .EvalSymlinks (projDir )
222
+ if err != nil {
223
+ return "" , err
206
224
}
207
- return os .Getwd ()
225
+
226
+ return realPath , nil
227
+ }
228
+
229
+ // Given any path, find its absolute path
230
+ func getAbsPath (path string ) (string , error ) {
231
+
232
+ var absPath string
233
+
234
+ if filepath .IsAbs (path ) {
235
+ // Already absolute path
236
+ absPath <
70C2
span class=pl-c1>= path
237
+ } else {
238
+ // Convert path from relative to absolute
239
+ newPath , err := filepath .Abs (path )
240
+ if err != nil {
241
+ return "" , err
242
+ }
243
+ absPath = newPath
244
+ }
245
+
246
+ return absPath , nil
208
247
}
You can’t perform that action at this time.
0 commit comments