-
Notifications
You must be signed in to change notification settings - Fork 424
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
Option descriptions not read from parent command resource bundle #1706
Comments
To clarify: you are saying that the (non-empty) description for And, the behaviour for options is different from the behaviour for things like the footer? That seems a bit strange, to be honest... Can you verify that this is really what is happening? Generally speaking, the easiest way with current picocli would be to have a single ResourceBundle that is set at the top-level command, that has all the keys for all commands. This can be done by prefixing the option names with the command name. For example:
One idea of how to manage this is could be to have separate teams manage separate resource bundles for their own modules, and merge them into a single bundle during the build. |
Your understanding is correct, this is what seems to be happening. I'm currently running our application through a debugger, will add a comment if I find out more details. Merging the bundles during the build is also an option, but that could potentially cause some other complications. For example, you can't have module-specific default descriptions. For example, multiple modules may have a |
I think the reason that this is working for footers and most/all other
If no footer is defined in the ModuleMessages bundle, I guess in order for this to work for options as well, the |
Thank you for the analysis of why footers work differently.
Yes, I think that would be a nice improvement. If you could create a PR with tests, that would be great! |
@remkop, I looked into having the Messages class take resource bundles from parent commands into account, but ran into an issue. Apparently, Extract from our code: // CommandLine construction
new CommandLine(FCLIRootCommands.class, micronautFactory)
// FCLIRootCommands
@Command(name="fcli", resourceBundle="...", subcommands={ConfigCommands.class, ...})
public class FCLIRootCommands { ... }
// ConfigCommands
@Command(name="config", resourceBundle="...", subcommands={...})
public class ConfigCommands { ... } For the
Is this behavior by design, or can this be considered a bug? Is there any other way for accessing the Edit: It turns out that this issue is caused by initialization order; apparently the Messages instance is constructed before the |
Hi @rsenden, that sounds strange, but I cannot reproduce the issue you describe. I tried with this test: public class HierarchyTest {
// FCLIRootCommands
@Command(name="fcli", /*resourceBundle="...",*/ subcommands={ConfigCommands.class})
public static class FCLIRootCommands { }
// ConfigCommands
@Command(name="config", /*resourceBundle="...",*/ subcommands={ConfigChild.class})
public static class ConfigCommands { }
@Command(name="config-child", /*resourceBundle="...",*/ subcommands={})
public static class ConfigChild { }
public static void main(String[] args) {
CommandLine.IFactory factory = CommandLine.defaultFactory();
CommandLine cmd = new CommandLine(FCLIRootCommands.class, factory);
print(cmd);
}
private static void print(CommandLine cl) {
Object userObject = cl.getCommand();
CommandLine.Model.CommandSpec spec = cl.getCommandSpec();
System.out.printf("%s.name=%s, parent.name=%s, root.name=%s%n",
userObject.getClass().getSimpleName(),
spec.name(),
spec.parent() == null ? "null-parent" : spec.parent().name(),
spec.root().name());
for (CommandLine c : cl.getSubcommands().values()) {
print(c);
}
}
} and it produces the following (correct-looking) output:
|
Oh, I see you edited your comment, and the issue is related to timing during the initialization phase. Understood. |
Hi @remkop, the following implementation of the Summary of changes, as visible here: fortify-ps@6530068
Any other ideas or suggestions for improvement? Next up would be to develop associated unit tests, not sure when I'll have time for that though. |
… i18n unit tests and fixed whitespace.
Suppose we have the following command hierarchy:
Behaviour:
usage.footer
in the RootMessages bundle, this footer will be displayed on all commands.option1
in the ModuleMessages bundle, anyoption1
in any of the leaf commands displays the proper description.option2
in the RootMessages bundle, anyoption2
in any of the leaf commands displays an empty descriptionSince our modules are maintained by different teams, we want to have a dedicated resource bundle for each module. However, as we also have some common options that are used throughout the application (mostly through generic mixins), we would like to define the descriptions for those generic options in the RootMessages bundle.
Unfortunately that doesn't seem to work, so for now we have to replicate those command option descriptions across every ModuleMessages bundle in each module. Obviously this is something that we would like to avoid.
Is there any way to make this work with the current picocli version, or will this require a fix in picocli?
The text was updated successfully, but these errors were encountered: