mirror of
https://gitlab.com/pnx/gosh
synced 2026-06-15 23:03:09 +02:00
26 lines
400 B
Go
26 lines
400 B
Go
package exit
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
func Exec(args []string) error {
|
|
if len(args) > 1 {
|
|
return errors.New("exit: ")
|
|
}
|
|
|
|
code := 0
|
|
if len(args) > 0 {
|
|
number, err := strconv.ParseUint(args[0], 10, 7)
|
|
if err != nil || number > 125 {
|
|
return fmt.Errorf("exit: %s must be an integer between 0 and 125", args[0])
|
|
}
|
|
code = int(number)
|
|
}
|
|
|
|
os.Exit(code)
|
|
return nil
|
|
}
|