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/command.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/command.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/config/command.go b/config/command.go new file mode 100644 index 0000000..34142cd --- /dev/null +++ b/config/command.go @@ -0,0 +1,32 @@ +package config + +import ( + "strings" + + "github.com/pkg/errors" +) + +func validateCommand(cmd string) error { + tokens := strings.Split(cmd, " ") + switch tokens[0] { + case "cp": + if len(tokens) != 3 { + return errors.New("cp command takes exactly two arguments") + } + case "exec": + if len(tokens) <= 1 { + return errors.New("exec command needs arguments") + } + case "mkdir": + if len(tokens) != 2 { + return errors.New("mkdir command takes exactly one argument") + } + case "wait": + if len(tokens) != 1 { + return errors.New("wait command takes no arguments") + } + default: + return errors.New("Invalid command : " + tokens[0]) + } + return nil +} |