From 8706b19ea15e99a9de46f8aefb55fbcdcad0f063 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 23 Feb 2020 16:37:12 +0100 Subject: parse config + logrus --- src/config.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/config.go b/src/config.go index 15ac082..44e9f21 100644 --- a/src/config.go +++ b/src/config.go @@ -1,16 +1,57 @@ package main -import "flag" +import ( + "flag" + "github.com/sirupsen/logrus" +) + +// parseConfig parses the config needed to start the game func parseConfig() Config { - verbose = flag.Bool("v", false, "verbose output") + + // bot configs + arch := flag.String("arch", "x86", "bot architecture (mips|arm|x86)") + bits := flag.Int("bits", 32, "bot bitness (8|16|32|64)") + maxProgSize := flag.Int("maxProgSize", 64, "the maximum bot size") + memPerBot := flag.Int("memPerBot", 512, "the amount of memory each bot should add to the arena") + gameRoundDuration := flag.Duration("t", 250, "The duration of a round") + + v := flag.Bool("v", false, "info") + vv := flag.Bool("vv", false, "debug") + vvv := flag.Bool("vvv", false, "trace") + + // parse the flags flag.Parse() + if *v == true { + logrus.SetLevel(logrus.InfoLevel) + } else if *vv == true { + logrus.SetLevel(logrus.DebugLevel) + } else if *vvv == true { + logrus.SetLevel(logrus.TraceLevel) + } else { + logrus.SetLevel(logrus.WarnLevel) + } + + // parse all trailing command line arguments as path to bot sourcecode + amountOfBots := flag.NArg() + + memsize := amountOfBots * *memPerBot + + logrus.WithFields(logrus.Fields{ + "mem per bot": *memPerBot, + "amountOfBots": amountOfBots, + "memsize": memsize, + }).Infof("Loaded config") + + // define a config to return config := Config{ - Arch: "x86", - Bits: 32, - Memsize: 1024, - MaxProgSize: 64, + Arch: *arch, + Bits: *bits, + Memsize: memsize, + MaxProgSize: *maxProgSize, + AmountOfBots: amountOfBots, + GameRoundDuration: *gameRoundDuration, } return config -- cgit 1.4.1