diff --git a/main.go b/main.go index b875d30..c843959 100644 --- a/main.go +++ b/main.go @@ -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) {