summaryrefslogtreecommitdiff
path: root/cmds/exit.go
blob: fc6d8525c6144d6d338f629f35e846ae44a7e9bd (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
}