mirror of
https://gitlab.com/EternalWanderer/sheet-parser.git
synced 2024-11-28 21:13:51 +01:00
Support for CHARSHEET env
This commit is contained in:
parent
d05e7447e5
commit
17c579ee49
19
main.go
19
main.go
|
@ -12,9 +12,10 @@ import (
|
||||||
"gitlab.com/EternalWanderer/dice-roller/Dice"
|
"gitlab.com/EternalWanderer/dice-roller/Dice"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const exampleFile string = "/etc/sheet-parser/example.json"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
path, skillString, saveString, statString string
|
path, pathFlag, skillString, saveString, statString string
|
||||||
exampleFile string = "/etc/sheet-parser/example.json"
|
|
||||||
modifier, diceThrows, surfaces int
|
modifier, diceThrows, surfaces int
|
||||||
X, Y int
|
X, Y int
|
||||||
char Character
|
char Character
|
||||||
|
@ -24,8 +25,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseFlags() {
|
func parseFlags() {
|
||||||
flag.StringVar(&path, "file", exampleFile, "Used to point to character sheet")
|
flag.StringVar(&pathFlag, "file", pathFlag, "Used to point to character sheet")
|
||||||
flag.StringVar(&path, "f", exampleFile, "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(&skillString, "skill", "", "Skill to parse")
|
||||||
flag.StringVar(&statString, "stat", "", "Stat check")
|
flag.StringVar(&statString, "stat", "", "Stat check")
|
||||||
flag.StringVar(&saveString, "save", "", "Saving throw to... throw")
|
flag.StringVar(&saveString, "save", "", "Saving throw to... throw")
|
||||||
|
@ -53,6 +54,16 @@ func isError(err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readJson() {
|
func readJson() {
|
||||||
|
envPath, isSet := os.LookupEnv("CHARSHEET")
|
||||||
|
switch {
|
||||||
|
case pathFlag != "":
|
||||||
|
path = pathFlag
|
||||||
|
case isSet:
|
||||||
|
path = envPath
|
||||||
|
default:
|
||||||
|
path = exampleFile
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("Opening file:", path)
|
fmt.Println("Opening file:", path)
|
||||||
var file, err = os.Open(path)
|
var file, err = os.Open(path)
|
||||||
if isError(err) {
|
if isError(err) {
|
||||||
|
|
Loading…
Reference in a new issue