add OptionCompleteHandler, better complete option

pull/1787/head
hengyunabc 4 years ago
parent b704e7cabd
commit 6a102d61b0

@ -355,4 +355,47 @@ public class CompletionUtils {
}
return false;
}
public static boolean completeOptions(Completion completion, List<OptionCompleteHandler> handlers) {
List<CliToken> tokens = completion.lineTokens();
/**
* <pre>
* ` --name a`tokens
* </pre>
*/
if (tokens.size() >= 3) {
CliToken cliToken_2 = tokens.get(tokens.size() - 2);
CliToken cliToken_3 = tokens.get(tokens.size() - 3);
if (cliToken_2.isBlank()) {
String token_3 = cliToken_3.value();
for (OptionCompleteHandler handler : handlers) {
if (handler.matchName(token_3)) {
return handler.complete(completion);
}
}
}
}
/**
* <pre>
* ` --name `tokens
* </pre>
*/
if (tokens.size() >= 2) {
CliToken cliToken_1 = tokens.get(tokens.size() - 1);
CliToken cliToken_2 = tokens.get(tokens.size() - 2);
if (cliToken_1.isBlank()) {
String token_2 = cliToken_2.value();
for (OptionCompleteHandler handler : handlers) {
if (handler.matchName(token_2)) {
return handler.complete(completion);
}
}
}
}
return false;
}
}

@ -0,0 +1,12 @@
package com.taobao.arthas.core.shell.cli;
/**
*
* @author hengyunabc 2021-04-29
*
*/
public interface OptionCompleteHandler {
boolean matchName(String token);
boolean complete(Completion completion);
}
Loading…
Cancel
Save