-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLI.java
More file actions
34 lines (28 loc) · 1.06 KB
/
Copy pathCLI.java
File metadata and controls
34 lines (28 loc) · 1.06 KB
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
import java.util.Scanner;
public class CLI {
private CommandHandler commandHandler;
public CLI() {
commandHandler = new CommandHandler();
}
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the Command Line Interpreter! Type 'help' to see available commands.");
while (true) {
// System.out.print("> ");
System.out.print(commandHandler.getCurrentDir());
System.out.print("> ");
String input = scanner.nextLine();
//handle exit case
if (input.equalsIgnoreCase("exit")) {
System.out.println("Exiting!");
break;
}
//parse input to get command and arguments
Parser commandParser = new Parser();
commandParser.parse(input);
//process and execute the command
commandHandler.handleCommands(commandParser.getCommandName(), commandParser.getArgs());
}
scanner.close();
}
}