Skip to content

Commit

Permalink
Add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Takumasa Sakao committed Oct 27, 2018
1 parent 3d5da5f commit 8eed836
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gdamore/tcell/encoding"
"github.com/sachaos/go-life/preset"
"github.com/urfave/cli"
"log"
)

func initScreen() tcell.Screen {
Expand Down Expand Up @@ -95,6 +96,25 @@ func main() {
app.Usage = "Conway's Game of Life"
app.Version = "0.2.0"

app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
},
}

app.Before = func(c *cli.Context) error {
if c.Bool("debug") {
log.SetOutput(os.Stderr)
} else {
file, err := os.Open(os.DevNull)
if err != nil {
return err
}
log.SetOutput(file)
}
return nil
}

app.Commands = []cli.Command{
{
Name: "themes",
Expand Down

0 comments on commit 8eed836

Please sign in to comment.