Skip to content

Commit

Permalink
Create a helper function to get AbsPaths and other file info in one f…
Browse files Browse the repository at this point in the history
…unction call. Reduces the amount of boilerplate code
  • Loading branch information
SwayKh committed Sep 18, 2024
1 parent e008dd2 commit 4780bbe
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"
"os"
"path/filepath"

"github.com/SwayKh/linksym/pkg/config"
)

// Handle the repeating function calls in one place
func filePathInfo(path string) (absPath string, exists bool, info os.FileInfo, err error) {
absPath, err = filepath.Abs(path)
if err != nil {
return "", false, nil, fmt.Errorf("Error getting absolute path of file %s", path)
}

exists, info, err = config.CheckFile(absPath)
if err != nil {
return "", false, nil, err
}
return absPath, exists, info, nil
}

0 comments on commit 4780bbe

Please sign in to comment.