Support for CHARSHEET env

This commit is contained in:
Nox Sluijtman 2022-08-28 15:45:47 +02:00
parent d05e7447e5
commit 17c579ee49

19
main.go
View file

@ -12,9 +12,10 @@ import (
"gitlab.com/EternalWanderer/dice-roller/Dice"
)
const exampleFile string = "/etc/sheet-parser/example.json"
var (
path, skillString, saveString, statString string
exampleFile string = "/etc/sheet-parser/example.json"
path, pathFlag, skillString, saveString, statString string
modifier, diceThrows, surfaces int
X, Y int
char Character
@ -24,8 +25,8 @@ var (
)
func parseFlags() {
flag.StringVar(&path, "file", exampleFile, "Used to point to character sheet")
flag.StringVar(&path, "f", exampleFile, "Used to point to character sheet")
flag.StringVar(&pathFlag, "file", pathFlag, "Used to point to character sheet")
flag.StringVar(&pathFlag, "f", pathFlag, "Used to point to character sheet")
flag.StringVar(&skillString, "skill", "", "Skill to parse")
flag.StringVar(&statString, "stat", "", "Stat check")
flag.StringVar(&saveString, "save", "", "Saving throw to... throw")
@ -53,6 +54,16 @@ func isError(err error) bool {
}
func readJson() {
envPath, isSet := os.LookupEnv("CHARSHEET")
switch {
case pathFlag != "":
path = pathFlag
case isSet:
path = envPath
default:
path = exampleFile
}
fmt.Println("Opening file:", path)
var file, err = os.Open(path)
if isError(err) {