diff options
author | Julien Dessaux | 2020-12-24 15:18:24 +0100 |
---|---|---|
committer | Julien Dessaux | 2020-12-24 15:18:24 +0100 |
commit | b4dc5d6841f7ded5995e5f308509b1a3a034cbed (patch) | |
tree | 254466925238c53bd51372a57558ec68fdf78205 /config/action.go | |
parent | Implemented the configuration file format (diff) | |
download | shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.gz shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.bz2 shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.zip |
Began implementing config validation
Diffstat (limited to '')
-rw-r--r-- | config/action.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/config/action.go b/config/action.go new file mode 100644 index 0000000..c63308e --- /dev/null +++ b/config/action.go @@ -0,0 +1,54 @@ +package config + +import ( + "strings" + + "github.com/pkg/errors" +) + +func validateAction(action string) error { + tokens := strings.Split(action, " ") + switch tokens[0] { + case "chmail": + if len(tokens) != 1 { + return errors.New("chmail action takes no arguments") + } + case "login": + if len(tokens) != 1 { + return errors.New("login action takes no arguments") + } + case "menu": + if len(tokens) != 2 { + return errors.New("menu action takes exactly one argument") + } + // menu existence is tested in global config + case "passwd": + if len(tokens) != 1 { + return errors.New("passwd action takes no arguments") + } + case "play": + if len(tokens) != 2 { + return errors.New("play action takes exactly one argument") + } + // game existence is tested in global config + case "register": + if len(tokens) != 1 { + return errors.New("register action takes no arguments") + } + case "replay": + if len(tokens) != 1 { + return errors.New("replay action takes no arguments") + } + case "watch": + if len(tokens) != 1 { + return errors.New("watch action takes no arguments") + } + case "quit": + if len(tokens) != 1 { + return errors.New("quit action takes no arguments") + } + default: + return errors.New("Invalid action : " + tokens[0]) + } + return nil +} |