Skip to content

Commit

Permalink
Create config struct and hydration from CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
eloylp committed Nov 19, 2019
1 parent e69ce9d commit f9a1aca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
22 changes: 22 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"flag"
)

type Cfg struct {
boardX, boardY, generations, intervalSecs int
}

func Config() Cfg {

c := Cfg{}

flag.IntVar(&c.boardX, "x", 50, "Size of row for the board")
flag.IntVar(&c.boardY, "y", 5, "Size of col for the board")
flag.IntVar(&c.generations, "g", 40, "Num of generations to process")
flag.IntVar(&c.intervalSecs, "i", 1, "Interval secs for board generation")
flag.Parse()

return c
}
11 changes: 4 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package main

func main() {
b := Board{
{false, false, false, false, true},
{false, true, false, false, true},
{false, true, true, false, false},
{false, true, false, false, true},
}
g := NewGame(b, 10, 1)

cfg := Config()
b := RandomBoard(cfg.boardX, cfg.boardY)
g := NewGame(b, cfg.generations, cfg.intervalSecs)
g.Run()
}

0 comments on commit f9a1aca

Please sign in to comment.