aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/command.go
blob: ad19142800a56a8c3cec07e9789a2ebef29df6d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package config

import (
	"fmt"
	"strings"
)

func validateCommand(cmd string) error {
	tokens := strings.Split(cmd, " ")
	switch tokens[0] {
	case "cp":
		if len(tokens) != 3 {
			return fmt.Errorf("cp command takes exactly two arguments")
		}
	case "exec":
		if len(tokens) <= 1 {
			return fmt.Errorf("exec command needs arguments")
		}
	case "mkdir":
		if len(tokens) != 2 {
			return fmt.Errorf("mkdir command takes exactly one argument")
		}
	case "wait":
		if len(tokens) != 1 {
			return fmt.Errorf("wait command takes no arguments")
		}
	default:
		return fmt.Errorf("Invalid command : " + tokens[0])
	}
	return nil
}