Bläddra i källkod

Handle `exit` in main REPL instead of ExitBuiltin.Run()

Alois Mahdal 3 dagar sedan
förälder
incheckning
a9c12566b8
3 ändrade filer med 7 tillägg och 2 borttagningar
  1. 4
    2
      app/builtin/builtin.go
  2. 1
    0
      app/core/core.go
  3. 2
    0
      app/main.go

+ 4
- 2
app/builtin/builtin.go Visa fil

@@ -151,8 +151,10 @@ func (self *ExitBuiltin) ParseArgs(ctx *core.Context, args []string) error {
151 151
 }
152 152
 
153 153
 func (self *ExitBuiltin) Run(ctx *core.Context) core.ActionResult {
154
-	os.Exit(0)
155
-	return wrapEs(0)
154
+	return core.ActionResult{
155
+		Code:       core.ActionResultCodeExit,
156
+		ExitStatus: 0,
157
+	}
156 158
 }
157 159
 
158 160
 //

+ 1
- 0
app/core/core.go Visa fil

@@ -29,4 +29,5 @@ const (
29 29
 	ActionResultCodeNoop ActionResultCode = iota
30 30
 	ActionResultCodeBuiltinCommand
31 31
 	ActionResultCodeExternalCommand
32
+	ActionResultCodeExit
32 33
 )

+ 2
- 0
app/main.go Visa fil

@@ -35,6 +35,8 @@ func repl(ctx *core.Context) {
35 35
 
36 36
 		result := runnable.Run(ctx)
37 37
 		switch result.Code {
38
+		case core.ActionResultCodeExit:
39
+			os.Exit(int(result.ExitStatus))
38 40
 		case core.ActionResultCodeNoop:
39 41
 		case core.ActionResultCodeBuiltinCommand:
40 42
 		case core.ActionResultCodeExternalCommand: