Skip to content

Commit

Permalink
<fix>(command): fix jline completion not contain all features key. (#837
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kyonRay authored Mar 15, 2024
1 parent f31bccd commit c2b56ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
77 changes: 35 additions & 42 deletions src/main/java/console/command/JlineUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,50 +187,39 @@ private static List<Completer> generateComplters(Client client) {
if (client.isEnableCommittee()) {
commands.add(AuthOpCommand.SET_SYS_CONFIG_PROPOSAL.getCommand());
}
Set<String> 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<BcosGroupInfo.GroupInfo> 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(
Expand Down

0 comments on commit c2b56ee

Please sign in to comment.