代码优化

This commit is contained in:
张家训
2026-06-08 18:04:23 +08:00
parent f5292ffa19
commit 213436c989
10 changed files with 161 additions and 266 deletions
@@ -1,8 +1,7 @@
package com.example.workutils;
import com.example.workutils.system.menu.MenuRunner;
import com.example.workutils.system.tool.Tool;
import com.example.workutils.system.tool.ToolRegistry;
import com.example.workutils.system.tool.Registry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
@@ -17,12 +16,10 @@ import java.util.Scanner;
@Slf4j
public class WorkUtilsApplication implements CommandLineRunner {
private final MenuRunner menuRunner;
private final ToolRegistry toolRegistry;
private final Registry registry;
public WorkUtilsApplication(MenuRunner menuRunner, ToolRegistry toolRegistry) {
this.menuRunner = menuRunner;
this.toolRegistry = toolRegistry;
public WorkUtilsApplication(Registry registry) {
this.registry = registry;
}
public static void main(String[] args) {
@@ -40,7 +37,7 @@ public class WorkUtilsApplication implements CommandLineRunner {
private void showInteractiveMenu() {
Scanner scanner = new Scanner(System.in);
menuRunner.run(scanner);
registry.runMainMenu(scanner);
}
/**
@@ -50,7 +47,7 @@ public class WorkUtilsApplication implements CommandLineRunner {
private void processCommand(String... args) throws Exception {
String command = args[0].toLowerCase();
Optional<Tool> toolOpt = toolRegistry.getToolByCommand(command);
Optional<Tool> toolOpt = registry.getToolByCommand(command);
if (toolOpt.isPresent()) {
Tool tool = toolOpt.get();
try {