github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/pogosh/builtins.go (about)

     1  // Copyright 2020 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package pogosh
     6  
     7  import (
     8  	"strconv"
     9  )
    10  
    11  // DefaultBuiltins lists all the available builtins.
    12  func DefaultBuiltins() map[string]Builtin {
    13  	return map[string]Builtin{
    14  		"exit": BuiltinExit,
    15  	}
    16  }
    17  
    18  // BuiltinExit implements the "exit" builtin.
    19  func BuiltinExit(s *State, cmd *Cmd) {
    20  	if len(cmd.argv) >= 2 {
    21  		code, err := strconv.Atoi(cmd.argv[1])
    22  		if err == nil {
    23  			s.Overrides.Exit(int(code))
    24  		}
    25  	}
    26  	s.Overrides.Exit(0)
    27  }