summaryrefslogtreecommitdiff
path: root/cmds/cmds.go
blob: f5b008112f6d9dd533429c2df1de8c0e8b985e22 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// cmds: handles system commands
package cmds

import (
	"strings"

	"gosh/global"
)

// Eval: evaluates a provided string into a command
// if it can't find the command or the arguments are incorrect
// returns an error
func Eval(cmd string) error {
	args := strings.Split(cmd, " ")
	switch args[0] {
	case "cd":
		if err := chDir(args); err != nil {
			return err
		}
		break
	case "export":
		if err := export(args); err != nil {
			return err
		}
		break
	case "unset":
		if err := unset(args); err != nil {
			return err
		}
		break
	case "set":
		if len(args) > 1 {
			set(args)
		} else {
			printEnv()
		}
		break
	case "test", "[":
		global.ReturnCode = test(args)
		break
	case "exit":
		if err := exit(args); err != nil {
			return err
		}
		break
	case ":":
		return nil
	}
	return nil
}