diff --git a/project/202506050323-王博-期末实验报告.docx b/project/202506050323-王博-期末实验报告.docx new file mode 100644 index 0000000..dba8476 Binary files /dev/null and b/project/202506050323-王博-期末实验报告.docx differ diff --git a/project/Command.class b/project/Command.class new file mode 100644 index 0000000..450409e Binary files /dev/null and b/project/Command.class differ diff --git a/project/Command.java b/project/Command.java new file mode 100644 index 0000000..4ac6bfe --- /dev/null +++ b/project/Command.java @@ -0,0 +1,9 @@ +package project.command; + +import project.view.CliView; + +public interface Command { + String getName(); + String getDescription(); + void execute(String[] args, CliView view); +} \ No newline at end of file diff --git a/project/CommandExecutor.class b/project/CommandExecutor.class new file mode 100644 index 0000000..78f96f1 Binary files /dev/null and b/project/CommandExecutor.class differ diff --git a/project/Main.java b/project/Main.java new file mode 100644 index 0000000..f0405d3 --- /dev/null +++ b/project/Main.java @@ -0,0 +1,41 @@ +package project; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; +import project.command.*; +import project.controller.CrawlController; +import project.view.CliView; + +public class Main { + private static boolean running = true; + + public static void main(String[] args) { + CliView view = new CliView(); + CrawlController controller = new CrawlController(); + + Map commands = new HashMap<>(); + commands.put("crawl", new CrawlCommand(controller, view)); + commands.put("help", new HelpCommand(commands)); + commands.put("exit", new ExitCommand(() -> running = false)); + + CommandExecutor executor = new CommandExecutor(commands, view); + + if (args.length > 0) { + String input = String.join(" ", args); + executor.execute(input); + return; + } + + view.printBanner(); + view.printHelp(commands); + + Scanner scanner = new Scanner(System.in); + while (running) { + view.printPrompt(); + String input = scanner.nextLine(); + executor.execute(input); + } + scanner.close(); + } +} \ No newline at end of file