瀏覽代碼

Minor cleanup for readability

Alois Mahdal 6 天之前
父節點
當前提交
8c8c3d273c
共有 1 個檔案被更改,包括 11 行新增1 行删除
  1. 11
    1
      app/main.go

+ 11
- 1
app/main.go 查看文件

145
 func handleCommand(ctx Context, command Command) ExitStatus {
145
 func handleCommand(ctx Context, command Command) ExitStatus {
146
 	// fmt.Printf("handleCommand():command=%#v\n", command)
146
 	// fmt.Printf("handleCommand():command=%#v\n", command)
147
 	switch command.command_type {
147
 	switch command.command_type {
148
+
148
 	case CommandTypeNone:
149
 	case CommandTypeNone:
149
 		return 0
150
 		return 0
151
+
150
 	case CommandTypeBuiltinExit:
152
 	case CommandTypeBuiltinExit:
151
 		os.Exit(0)
153
 		os.Exit(0)
154
+
152
 	case CommandTypeBuiltinEcho:
155
 	case CommandTypeBuiltinEcho:
153
 		fmt.Fprintln(ctx.stdout, strings.Join(command.tokens[1:], " "))
156
 		fmt.Fprintln(ctx.stdout, strings.Join(command.tokens[1:], " "))
157
+		return 0
158
+
154
 	case CommandTypeBuiltinPwd:
159
 	case CommandTypeBuiltinPwd:
155
 		if len(command.tokens) != 1 {
160
 		if len(command.tokens) != 1 {
156
 			fmt.Fprintln(ctx.stderr, "usage: pwd")
161
 			fmt.Fprintln(ctx.stderr, "usage: pwd")
161
 			panic("error getting current working directory")
166
 			panic("error getting current working directory")
162
 		}
167
 		}
163
 		fmt.Fprintln(ctx.stdout, cwd_path)
168
 		fmt.Fprintln(ctx.stdout, cwd_path)
169
+		return 0
170
+
164
 	case CommandTypeBuiltinType:
171
 	case CommandTypeBuiltinType:
165
 		if len(command.tokens) != 2 {
172
 		if len(command.tokens) != 2 {
166
 			fmt.Fprintln(ctx.stderr, "usage: type COMMAND")
173
 			fmt.Fprintln(ctx.stderr, "usage: type COMMAND")
179
 		default:
186
 		default:
180
 			fmt.Fprintf(ctx.stdout, "%s is a shell builtin\n", parsed.tokens[0])
187
 			fmt.Fprintf(ctx.stdout, "%s is a shell builtin\n", parsed.tokens[0])
181
 		}
188
 		}
189
+		return 0
190
+
182
 	case CommandTypeExternal:
191
 	case CommandTypeExternal:
183
 		cmd := exec.Command(command.exec_path, command.tokens[1:]...)
192
 		cmd := exec.Command(command.exec_path, command.tokens[1:]...)
184
 		cmd.Args = command.tokens
193
 		cmd.Args = command.tokens
195
 				return ExitStatus(65535)
204
 				return ExitStatus(65535)
196
 			}
205
 			}
197
 		}
206
 		}
198
-		return ExitStatus(0)
207
+		return 0
208
+
199
 	default:
209
 	default:
200
 		panic("unknown command type")
210
 		panic("unknown command type")
201
 	}
211
 	}