forked from Drive-for-Java/MyCMD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellEngine.java
More file actions
36 lines (28 loc) · 924 Bytes
/
Copy pathShellEngine.java
File metadata and controls
36 lines (28 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.mycmd;
import java.io.IOException;
import java.util.Arrays;
/** Central execution engine. */
public class ShellEngine {
private final CommandRegistry registry;
private final ShellContext context;
public ShellEngine(CommandRegistry registry, ShellContext context) {
this.registry = registry;
this.context = context;
}
public void execute(String input) {
if (input == null || input.trim().isEmpty()) return;
String[] parts = input.trim().split("\\s+");
String cmdName = context.resolveAlias(parts[0]);
String[] args = Arrays.copyOfRange(parts, 1, parts.length);
Command cmd = registry.get(cmdName);
if (cmd == null) {
System.out.println("❌ Unknown command: " + cmdName);
return;
}
try {
cmd.execute(args, context);
} catch (IOException e) {
System.out.println("⚠️ Error executing command: " + e.getMessage());
}
}
}