@Test public void testMessagesGetStringArrayNullKey() { String[] def = {"abc"}; assertSame(def, new Messages(CommandSpec.create(), (ResourceBundle) null).getStringArray(null, def)); assertSame(def, new Messages(CommandSpec.create(), (ResourceBundle) null).getStringArray("help", def)); ResourceBundle rb = ResourceBundle.getBundle("picocli.SharedMessages"); assertSame(def, new Messages(CommandSpec.create(), rb).getStringArray(null, def)); assertNotEquals(def, new Messages(CommandSpec.create(), rb).getStringArray("usage.description", def)); } }
@Test public void testMessagesGetStringArrayNullKey() { String[] def = {"abc"}; assertSame(def, new Messages(CommandSpec.create(), null).getStringArray(null, def)); assertSame(def, new Messages(CommandSpec.create(), null).getStringArray("help", def)); ResourceBundle rb = ResourceBundle.getBundle("picocli.SharedMessages"); assertSame(def, new Messages(CommandSpec.create(), rb).getStringArray(null, def)); assertNotEquals(def, new Messages(CommandSpec.create(), rb).getStringArray("usage.description", def)); } }
/** Returns the description template of this positional parameter, before variables are {@linkplain Parameters#description() rendered}. * If a resource bundle has been {@linkplain ArgSpec#messages(Messages) set}, this method will first try to find a value in the resource bundle: * If the resource bundle has no entry for the {@code fully qualified commandName + "." + descriptionKey} or for the unqualified {@code descriptionKey}, * an attempt is made to find the positional parameter description using {@code paramLabel() + "[" + index() + "]"} as key, * first with the {@code fully qualified commandName + "."} prefix, then without. * @see Parameters#description() * @see CommandSpec#qualifiedName(String) * @since 3.6 */ @Override public String[] description() { if (messages() == null) { return super.description(); } String[] newValue = messages().getStringArray(descriptionKey(), null); if (newValue != null) { return newValue; } newValue = messages().getStringArray(paramLabel() + "[" + index() + "]", null); if (newValue != null) { return newValue; } return super.description(); }
/** Returns the description template of this option, before variables are {@linkplain Option#description() rendered}. * If a resource bundle has been {@linkplain ArgSpec#messages(Messages) set}, this method will first try to find a value in the resource bundle: * If the resource bundle has no entry for the {@code fully qualified commandName + "." + descriptionKey} or for the unqualified {@code descriptionKey}, * an attempt is made to find the option description using any of the option names (without leading hyphens) as key, * first with the {@code fully qualified commandName + "."} prefix, then without. * @see CommandSpec#qualifiedName(String) * @see Option#description() */ @Override public String[] description() { if (messages() == null) { return super.description(); } String[] newValue = messages().getStringArray(descriptionKey(), null); if (newValue != null) { return newValue; } for (String name : names()) { newValue = messages().getStringArray(CommandSpec.stripPrefix(name), null); if (newValue != null) { return newValue; } } return super.description(); }
private String[] resourceArr(String key) { return messages == null ? null : messages.getStringArray(key, null); }
/** Returns the description template of this option, before variables are {@linkplain Option#description() rendered}. * If a resource bundle has been {@linkplain ArgSpec#messages(Messages) set}, this method will first try to find a value in the resource bundle: * If the resource bundle has no entry for the {@code fully qualified commandName + "." + descriptionKey} or for the unqualified {@code descriptionKey}, * an attempt is made to find the option description using any of the option names (without leading hyphens) as key, * first with the {@code fully qualified commandName + "."} prefix, then without. * @see CommandSpec#qualifiedName(String) * @see Option#description() */ @Override public String[] description() { if (messages() == null) { return super.description(); } String[] newValue = messages().getStringArray(descriptionKey(), null); if (newValue != null) { return newValue; } for (String name : names()) { newValue = messages().getStringArray(CommandSpec.stripPrefix(name), null); if (newValue != null) { return newValue; } } return super.description(); }
private String[] resourceArr(String key) { return messages == null ? null : messages.getStringArray(key, null); }
/** Returns the description template of this positional parameter, before variables are {@linkplain Parameters#description() rendered}. * If a resource bundle has been {@linkplain ArgSpec#messages(Messages) set}, this method will first try to find a value in the resource bundle: * If the resource bundle has no entry for the {@code fully qualified commandName + "." + descriptionKey} or for the unqualified {@code descriptionKey}, * an attempt is made to find the positional parameter description using {@code paramLabel() + "[" + index() + "]"} as key, * first with the {@code fully qualified commandName + "."} prefix, then without. * @see Parameters#description() * @see CommandSpec#qualifiedName(String) * @since 3.6 */ @Override public String[] description() { if (messages() == null) { return super.description(); } String[] newValue = messages().getStringArray(descriptionKey(), null); if (newValue != null) { return newValue; } newValue = messages().getStringArray(paramLabel() + "[" + index() + "]", null); if (newValue != null) { return newValue; } return super.description(); }