-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completionCandidates() called during help output even if not going to be used #1351
Comments
I see, interesting. |
I'll see what I can do, but probably not for some time. Busy myself :) I'm also on an older version picocli right now, which looks like might require some changes on my side to upgrade to latest. We'll have to look at that later. |
Hello, I wonder if this issue is still open, and I would like to work on this issue :). |
@Lanninger08 Hi! Great pull requests include tests and documentation (docs not always needed, like for bug fixes). Also nice to be consistent with the existing code style (spaces vs tabs, code layout etc), but that is not documented and I'm flexible. Thanks for offering to spend time on this! |
Hi! @remkop private String[] expandVariables(String[] desc) {
if (desc.length == 0) { return desc; }
StringBuilder candidates = new StringBuilder();
if (completionCandidates() != null) {
System.out.println("invoked here!");
for (String c : completionCandidates()) {
if (candidates.length() > 0) { candidates.append(", "); }
candidates.append(c);
}
}
String defaultValueString = defaultValueString(false); // interpolate later
String fallbackValueString = isOption() ? ((OptionSpec) this).fallbackValue : ""; // interpolate later
String mapFallbackValueString = String.valueOf(mapFallbackValue); // interpolate later
String[] result = new String[desc.length];
for (int i = 0; i < desc.length; i++) {
result[i] = format(desc[i].replace(DESCRIPTION_VARIABLE_DEFAULT_VALUE, defaultValueString.replace("%", "%%"))
.replace(DESCRIPTION_VARIABLE_FALLBACK_VALUE, fallbackValueString.replace("%", "%%"))
.replace(DESCRIPTION_VARIABLE_MAP_FALLBACK_VALUE, mapFallbackValueString.replace("%", "%%"))
.replace(DESCRIPTION_VARIABLE_COMPLETION_CANDIDATES, candidates.toString()));
}
return interpolate(result);
} |
@Lanninger08 @Command(description = {
"line 1",
"line 2",
"line 3"})
class Example {
@Option(name = "-x", description = {
"line 1",
"line 2",
"line 3"})
String x;
} |
…ates` optimization
…onCandidates` optimization" This reverts commit 05d952d.
This reverts commit fabab83.
This reverts commit 1280ae7.
…onCandidates` optimization" This reverts commit 05d952d.
This reverts commit fabab83.
This reverts commit 1280ae7.
@remkop I am excited to see this issue fixed in upcoming release, but it's been a while since 4.6.1 was done. Any plan/word on when 4.6.2 will be released? Thanks. |
@vstriz picocli 4.6.2 has just been released. Enjoy! |
I have some cli commands that interact with the server. One of parameters has a completionCandidates setting that talks to the server to figure out the list of possible values, which can be dynamic. It looks like when I ask for "--help" of the command it also invokes the completionCandidates, even though the result is not going to be used. It gets it just in case it will need to use in the description if
"${COMPLETION-CANDIDATES}"
is specified. But in my case it's not used in description. My situation is even worse, sometimes I have no connection to the server, and therefore I'm unable to display the command help at all.It would be nice, and more optimal in case of expensive operation, if the completionCandidates for help of commands was invoked only if needed. I.e. when
"${COMPLETION-CANDIDATES}"
is actually specified in description.The code in question is in
picocli.CommandLine.Model.ArgSpec.expandVariables(String[])
The text was updated successfully, but these errors were encountered: