Skip to content

Commit 80bb882

Browse files
Update ShellContext.java
1 parent f0025c4 commit 80bb882

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/main/java/com/mycmd/ShellContext.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,33 @@ public ShellContext() {
2929
this.aliases = new HashMap<>();
3030
this.commandHistory = new ArrayList<>();
3131
this.startTime = Instant.now();
32+
this.scanner = null; // Will be set by App.java
3233
loadAliases();
3334
}
3435

36+
// ==================== Scanner Management ====================
37+
38+
/**
39+
* Set the shared Scanner instance for all commands to use.
40+
* Should only be called once by App.java during initialization.
41+
*/
42+
public void setScanner(Scanner scanner) {
43+
this.scanner = scanner;
44+
}
45+
46+
/**
47+
* Get the shared Scanner instance.
48+
* All commands should use this instead of creating their own Scanner.
49+
* @return the shared Scanner instance
50+
* @throws IllegalStateException if Scanner hasn't been initialized
51+
*/
52+
public Scanner getScanner() {
53+
if (scanner == null) {
54+
throw new IllegalStateException("Scanner not initialized in ShellContext");
55+
}
56+
return scanner;
57+
}
58+
3559
public void addToHistory(String command) {
3660
history.add(command);
3761
commandHistory.add(command);

0 commit comments

Comments
 (0)