Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Use executable location as working directory
Browse files Browse the repository at this point in the history
Ensures config.json is found when F1viewer is called from elsewhere
  • Loading branch information
peskdale committed Apr 25, 2019
1 parent ff96fc1 commit 3a9f087
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -55,10 +56,27 @@ var infoTable *tview.Table
var debugText *tview.TextView
var tree *tview.TreeView

var (
_ = determineWorkingDirectory()
configFile = "config.json"
)

func determineWorkingDirectory() string {
// Get the absolute path this executable is located in.
executablePath, err := os.Executable()
if err != nil {
debugPrint("Error: Couldn't determine working directory:")
debugPrint(err.Error())
}
// Set the working directory to the path the executable is located in.
os.Chdir(filepath.Dir(executablePath))
return ""
}

func main() {
//start UI
app = tview.NewApplication()
file, err := ioutil.ReadFile("config.json")
file, err := ioutil.ReadFile(configFile)
con.CheckUpdate = true
con.Lang = "en"
if err != nil {
Expand Down

0 comments on commit 3a9f087

Please # to comment.