Skip to content

Commit a7cb1e5

Browse files
committed
fix setup for windows and macos
1 parent 8ae95a4 commit a7cb1e5

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

cmd/setup/main.go

+21-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"golang.org/x/term"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"runtime"
1213
"strconv"
1314
"strings"
@@ -61,16 +62,25 @@ func runCommand(command string, args ...string) error {
6162
}
6263

6364
func main() {
64-
var tibulaCommand = "./tibula"
65+
var cwd = filepath.Dir(os.Args[0])
66+
var tibulaCommand = filepath.Join(cwd, "tibula")
67+
var tibulaJson = filepath.Join(cwd, "tibula.json")
68+
var tibulaDb = filepath.Join(cwd, "tibula.db")
69+
6570
if osType() == "windows" {
66-
tibulaCommand = ".\tibula.exe"
71+
tibulaCommand += ".exe"
72+
}
73+
74+
if _, err := os.Stat(tibulaCommand); err != nil {
75+
fmt.Println("Cannot find tibula on the current folder, please copy it here and try again.")
76+
exit()
6777
}
6878

6979
sys.Configure()
70-
if _, err := os.Stat("tibula.json"); err == nil {
80+
if _, err := os.Stat(tibulaJson); err == nil {
7181
start := prompt("A configuration file already exists. Do you want to start Tibula instead? (Y/n)")
7282
if strings.ToLower(start) != "n" {
73-
if err := sys.ConfigRead("tibula.json"); err != nil {
83+
if err := sys.ConfigRead(tibulaJson); err != nil {
7484
fmt.Println(err)
7585
exit()
7686
}
@@ -79,7 +89,7 @@ func main() {
7989
} else {
8090
openBrowser(fmt.Sprintf("http://%s:%d", sys.Options.WebHost, sys.Options.WebPort))
8191
}
82-
runCommand(tibulaCommand, "--config", "tibula.json", "--start")
92+
runCommand(tibulaCommand, "--config", tibulaJson, "--start")
8393
exit()
8494
}
8595
}
@@ -132,8 +142,10 @@ func main() {
132142
}
133143
} else {
134144
sys.Options.DbPort = 0
135-
dbName := prompt("Database file name (tibula.db)")
136-
if dbName != "" {
145+
dbName := prompt(fmt.Sprintf("Database file name (%s)", tibulaDb))
146+
if dbName == "" {
147+
sys.Options.DbName = tibulaDb
148+
} else {
137149
sys.Options.DbName = dbName
138150
}
139151
}
@@ -146,9 +158,9 @@ func main() {
146158
if logLevel != "" {
147159
sys.Options.LogLevel, _ = strconv.Atoi(logLevel)
148160
}
149-
jsonFile := prompt("Config file (tibula.json)")
161+
jsonFile := prompt(fmt.Sprintf("Config file (%s)", tibulaJson))
150162
if jsonFile == "" {
151-
jsonFile = "tibula.json"
163+
jsonFile = tibulaJson
152164
}
153165

154166
//setup

0 commit comments

Comments
 (0)