代码优化提交
This commit is contained in:
@@ -41,19 +41,18 @@ public class WorkUtilsApplication implements CommandLineRunner {
|
||||
}
|
||||
|
||||
/**
|
||||
* 命令行模式:通过 PluginManager 按命令名分发到对应 Plugin
|
||||
* 命令行模式:通过 PluginManager 按命令名分发到对应 Tool
|
||||
* 启动类不依赖任何具体业务 Service
|
||||
*/
|
||||
private void processCommand(String... args) throws Exception {
|
||||
String command = args[0].toLowerCase();
|
||||
|
||||
Optional<Plugin> pluginOpt = pluginManager.getPluginByCommand(command);
|
||||
if (pluginOpt.isPresent()) {
|
||||
Plugin plugin = pluginOpt.get();
|
||||
Optional<Plugin> toolOpt = pluginManager.getPluginByCommand(command);
|
||||
if (toolOpt.isPresent()) {
|
||||
Plugin plugin = toolOpt.get();
|
||||
try {
|
||||
// args[0]是命令名,从args[1]开始传给plugin
|
||||
String[] pluginArgs = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0];
|
||||
plugin.executeCommand(pluginArgs);
|
||||
String[] toolArgs = args.length > 1 ? Arrays.copyOfRange(args, 1, args.length) : new String[0];
|
||||
plugin.executeCommand(toolArgs);
|
||||
} catch (Exception e) {
|
||||
log.error("命令执行失败: {} [{}]", plugin.getName(), plugin.getId(), e);
|
||||
System.err.println("命令执行失败: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user