Skip to content

Commit

Permalink
Remove redundant code (RE: absolute path, cwd)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinekt4 committed Mar 11, 2022
1 parent adc81de commit 090cbd1
Showing 1 changed file with 3 additions and 42 deletions.
45 changes: 3 additions & 42 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,49 +199,10 @@ func initConfig() {

func getProjectDir(dir string) (string, error) {

var projDir string

if dir != "" {
// Get Absolute Path
absPath, err := getAbsPath(dir)
if err != nil {
return "", err
}
projDir = absPath

} else {
// Get Current Working Dir
cwd, err := os.Getwd()
if err != nil {
return "", err
}
projDir = cwd
}
// Let us evaluate the symlinks
realPath, err := filepath.EvalSymlinks(projDir)
if err != nil {
var err error
if dir, err = filepath.Abs(dir); err != nil {
return "", err
}

return realPath, nil
}

// Given any path, find its absolute path
func getAbsPath(path string) (string, error) {

var absPath string

if filepath.IsAbs(path) {
// Already absolute path
absPath = path
} else {
// Convert path from relative to absolute
newPath, err := filepath.Abs(path)
if err != nil {
return "", err
}
absPath = newPath
}

return absPath, nil
return filepath.EvalSymlinks(dir)
}

0 comments on commit 090cbd1

Please sign in to comment.