summaryrefslogtreecommitdiff
path: root/cmds/cmds.go
blob: bc521dd50d280f12e84ac4cb9d98dd90d0abf199 (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
51
52
// cmds: handles system commands
package cmds

import (
	"fmt"
	"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)
		fmt.Println(global.ReturnCode)
		break
	case "exit":
		if err := exit(args); err != nil {
			return err
		}
		break
	case ":":
		return nil
	}
	return nil
}