Skip to content

Commit 1197296

Browse files
committed
fix: default root folder set to where the binary is instead of current directory
1 parent 3074b75 commit 1197296

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

cmd/runtipi/main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"github.com/runtipi/cli/internal/commands"
89
"github.com/runtipi/cli/internal/config"
@@ -20,9 +21,23 @@ var (
2021
func init() {
2122
var err error
2223

23-
config.RootFolder, err = os.Getwd()
24+
binaryPath, err := os.Executable()
2425
if err != nil {
25-
fmt.Println("Error getting working directory:", err)
26+
fmt.Println("Error getting executable path:", err)
27+
os.Exit(1)
28+
}
29+
30+
evalPath, err := filepath.EvalSymlinks(binaryPath)
31+
if err != nil {
32+
fmt.Println("Error getting binary directory:", err)
33+
os.Exit(1)
34+
}
35+
36+
executableDir := filepath.Dir(evalPath)
37+
config.RootFolder, err = filepath.Abs(executableDir)
38+
39+
if err != nil {
40+
fmt.Println("Error getting absolute path for root folder:", err)
2641
os.Exit(1)
2742
}
2843

0 commit comments

Comments
 (0)