Skip to content

Commit 0aa4706

Browse files
committed
Avoid crashing if no game is provided
Improve log file path creation.
1 parent b7099d0 commit 0aa4706

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cmd/gork/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"log"
77
"os"
8+
"path"
89
"strings"
910

1011
"github.com/d-dorazio/gork/gork"
@@ -13,6 +14,7 @@ import (
1314
func main() {
1415
if len(os.Args) < 2 {
1516
fmt.Println("Please provide a game")
17+
return
1618
}
1719

1820
story := os.Args[1]
@@ -22,7 +24,7 @@ func main() {
2224
panic(err)
2325
}
2426

25-
logfile, err := os.Create(strings.Split(story, ".")[0] + ".log")
27+
logfile, err := os.Create(storyLogFilename(story))
2628
if err != nil {
2729
panic(err)
2830
}
@@ -35,6 +37,13 @@ func main() {
3537
header := gork.NewZHeader(mem)
3638

3739
gork.NewZMachine(mem, header, gork.ZTerminal{}).InterpretAll()
40+
}
3841

39-
fmt.Println("")
42+
func storyLogFilename(story string) string {
43+
name := path.Base(story)
44+
tmp := strings.Split(name, ".")
45+
if len(tmp) > 1 {
46+
name = tmp[0]
47+
}
48+
return name + ".log"
4049
}

0 commit comments

Comments
 (0)