From c3263c03776401ad1263a9fb8f5a44a8ed44d61b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 17 Nov 2021 10:13:06 +0100 Subject: Refactored package structure --- pkg/config/command.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pkg/config/command.go (limited to 'pkg/config/command.go') diff --git a/pkg/config/command.go b/pkg/config/command.go new file mode 100644 index 0000000..34142cd --- /dev/null +++ b/pkg/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 +} -- cgit v1.2.3