diff --git a/build.gradle b/build.gradle index a1cfe501..dd61c4ef 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ dependencies { exclude group: "org.slf4j" } implementation('commons-cli:commons-cli:1.5.0') - implementation('org.jline:jline:3.25.0') + implementation('org.jline:jline:3.21.0') implementation('io.bretty:console-table-builder:1.2') implementation('com.github.jsqlparser:jsqlparser:2.0') implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.5.0-SNAPSHOT') { diff --git a/src/main/java/console/command/JlineUtils.java b/src/main/java/console/command/JlineUtils.java index aa870f02..c75dc6f8 100644 --- a/src/main/java/console/command/JlineUtils.java +++ b/src/main/java/console/command/JlineUtils.java @@ -17,8 +17,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Optional; +import java.util.Set; import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.response.BcosGroupInfo; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigFeature; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigService; import org.fisco.bcos.sdk.v3.model.EnumNodeVersion; @@ -183,50 +187,39 @@ private static List generateComplters(Client client) { if (client.isEnableCommittee()) { commands.add(AuthOpCommand.SET_SYS_CONFIG_PROPOSAL.getCommand()); } + Set keys = new HashSet<>(); + keys.add(SystemConfigService.TX_COUNT_LIMIT); + keys.add(SystemConfigService.TX_GAS_LIMIT); + keys.add(SystemConfigService.TX_GAS_PRICE); + keys.add(SystemConfigService.CONSENSUS_PERIOD); + keys.add(SystemConfigService.COMPATIBILITY_VERSION); + keys.add(SystemConfigService.AUTH_STATUS); + for (SystemConfigFeature.Features feature : SystemConfigFeature.Features.values()) { + if (client.getChainCompatibilityVersion() + .compareTo(EnumNodeVersion.convertToVersion(feature.enableVersion())) + >= 0) { + keys.add(feature.toString()); + } + } + Optional group = + client.getGroupInfoList() + .getResult() + .stream() + .filter(groupInfo -> groupInfo.getGroupID().equals(client.getGroup())) + .findFirst(); + if (group.isPresent() && !group.get().getNodeList().isEmpty()) { + group.get() + .getNodeList() + .forEach(groupNodeInfo -> keys.addAll(groupNodeInfo.getFeatureKeys())); + } for (String command : commands) { - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.TX_COUNT_LIMIT), - new StringsCompleterIgnoreCase())); - - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.TX_GAS_LIMIT), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.TX_GAS_PRICE), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.CONSENSUS_PERIOD), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.COMPATIBILITY_VERSION), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.AUTH_STATUS), - new StringsCompleterIgnoreCase())); - for (SystemConfigFeature.Features feature : SystemConfigFeature.Features.values()) { - if (client.getChainCompatibilityVersion() - .compareTo( - EnumNodeVersion.convertToVersion(feature.enableVersion())) - >= 0) { - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(feature.toString()), - new StringsCompleterIgnoreCase())); - } + for (String key : keys) { + completers.add( + new ArgumentCompleter( + new StringsCompleter(command), + new StringsCompleter(key), + new StringsCompleterIgnoreCase())); } } completers.add(