From 17c579ee495c8afb4e2a9d105456224a1ef5d280 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Sun, 28 Aug 2022 15:45:47 +0200 Subject: [PATCH] Support for CHARSHEET env --- main.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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) {