summaryrefslogtreecommitdiff
path: root/cmds/exit.go
blob: 52f082ae224f58f2e722b678e72e87957eb85e94 (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
package cmds

import (
	"errors"
	"os"
	"strconv"

	"gosh/global"
)

// exit the shell and returns the provided status
// if no status is specified returns 0
func exit(args []string) error {
	status := global.ReturnCode
	if len(args) > 1 {
		var err error
		status, err = strconv.Atoi(args[1])
		if err != nil {
			return errors.New("usage: exit (status)")
		}
	}
	os.Exit(status)
	return nil
}