Skip to content

Commit

Permalink
[#795] showAtFileInUsageHelp bugfix (ResourceBundles were not used), …
Browse files Browse the repository at this point in the history
…added tests
  • Loading branch information
remkop committed Jan 28, 2020
1 parent d122d35 commit 9619960
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/main/java/picocli/CommandLine.java
Expand Up @@ -13257,6 +13257,7 @@ protected Text createDetailedSynopsisPositionalsText(Collection<ArgSpec> done) {
List<PositionalParamSpec> positionals = new ArrayList<PositionalParamSpec>(commandSpec.positionalParameters()); // iterate in declaration order
if (commandSpec.parser.expandAtFiles() && commandSpec.usageMessage.showAtFileInUsageHelp()) {
positionals.add(0, AT_FILE_POSITIONAL_PARAM);
AT_FILE_POSITIONAL_PARAM.messages(commandSpec.usageMessage().messages());
}
positionals.removeAll(done);
for (PositionalParamSpec positionalParam : positionals) {
Expand Down Expand Up @@ -13352,6 +13353,7 @@ private int calcLongOptionColumnWidth() {
List<PositionalParamSpec> positionals = new ArrayList<PositionalParamSpec>(commandSpec.positionalParameters()); // iterate in declaration order
if (commandSpec.parser.expandAtFiles() && commandSpec.usageMessage.showAtFileInUsageHelp()) {
positionals.add(0, AT_FILE_POSITIONAL_PARAM);
AT_FILE_POSITIONAL_PARAM.messages(commandSpec.usageMessage().messages());
}
//IParameterRenderer paramRenderer = new DefaultParameterRenderer(false, " ");
for (PositionalParamSpec positional : positionals) {
Expand Down Expand Up @@ -13429,6 +13431,7 @@ public String parameterList(Layout layout, IParamLabelRenderer paramLabelRendere
List<PositionalParamSpec> positionals = new ArrayList<PositionalParamSpec>(commandSpec.positionalParameters());
if (commandSpec.parser.expandAtFiles() && commandSpec.usageMessage.showAtFileInUsageHelp()) {
positionals.add(0, AT_FILE_POSITIONAL_PARAM);
AT_FILE_POSITIONAL_PARAM.messages(commandSpec.usageMessage().messages());
}
List<ArgGroupSpec> groups = optionListGroups();
for (ArgGroupSpec group : groups) { positionals.removeAll(group.positionalParameters()); }
Expand Down
31 changes: 17 additions & 14 deletions src/test/java/picocli/AtFileTest.java
Expand Up @@ -617,7 +617,8 @@ class App {

@Test
public void testShowAtFileInUsageHelpBasic() {
@Command(name = "A", mixinStandardHelpOptions = true, showAtFileInUsageHelp = true, description = "... description ...")
@Command(name = "A", mixinStandardHelpOptions = true,
showAtFileInUsageHelp = true, description = "... description ...")
class A { }

String actual = new CommandLine(new A()).getUsageMessage();
Expand All @@ -632,8 +633,10 @@ class A { }

@Test
public void testShowAtFileInUsageHelpSystemProperties() {
@Command(name = "A", mixinStandardHelpOptions = true, showAtFileInUsageHelp = true, description = "... description ...")
@Command(name = "A", mixinStandardHelpOptions = true,
showAtFileInUsageHelp = true, description = "... description ...")
class A { }

System.setProperty("picocli.atfile.label", "my@@@@file");
System.setProperty("picocli.atfile.description", "@files rock!");

Expand All @@ -647,19 +650,19 @@ class A { }
assertEquals(expected, actual);
}

static class MyResourceBundle extends ListResourceBundle {
public static class MyResourceBundle extends ListResourceBundle {
protected Object[][] getContents() {
return new Object[][] {
{"picocli.atfile", "hi! I amd the @file description from a file"},
{"@<filename>", "BUNDLE@FILE"},
{"my@@@@file", "OTHER@@@"},
{"@<filename>", "BUNDLE@FILE"}, // ignored...
{"my@@@@file", "OTHER@@@"}, // ignored...
};
}
}
@Ignore

@Test
public void testShowAtFileInUsageHelpResourceBundleWithSystemProps() {
@Command(name = "A", mixinStandardHelpOptions = true, //resourceBundle = "picocli.AtFileTest$MyResourceBundle",
@Command(name = "A", mixinStandardHelpOptions = true, resourceBundle = "picocli.AtFileTest$MyResourceBundle",
showAtFileInUsageHelp = true, description = "... description ...")
class A { }

Expand All @@ -668,25 +671,25 @@ class A { }

String actual = new CommandLine(new A()).setResourceBundle(new MyResourceBundle()).getUsageMessage();
String expected = String.format("" +
"Usage: A [-hV] [@<filename>...]%n" +
"Usage: A [-hV] [my@@@@file...]%n" +
"... description ...%n" +
" [OTHER@@@...] hi! I amd the @file description from a file%n" +
" -h, --help Show this help message and exit.%n" +
" -V, --version Print version information and exit.%n");
" [my@@@@file...] hi! I amd the @file description from a file%n" +
" -h, --help Show this help message and exit.%n" +
" -V, --version Print version information and exit.%n");
assertEquals(expected, actual);
}
@Ignore

@Test
public void testShowAtFileInUsageHelpResourceBundleWithoutSystemProps() {
@Command(name = "A", mixinStandardHelpOptions = true, resourceBundle = "picocli.AtFileTest.MyResourceBundle",
@Command(name = "A", mixinStandardHelpOptions = true, resourceBundle = "picocli.AtFileTest$MyResourceBundle",
showAtFileInUsageHelp = true, description = "... description ...")
class A { }

String actual = new CommandLine(new A()).getUsageMessage();
String expected = String.format("" +
"Usage: A [-hV] [@<filename>...]%n" +
"... description ...%n" +
" [BUNDLE@FILE...] hi! I amd the @file description from a file%n" +
" [@<filename>...] hi! I amd the @file description from a file%n" +
" -h, --help Show this help message and exit.%n" +
" -V, --version Print version information and exit.%n");
assertEquals(expected, actual);
Expand Down

0 comments on commit 9619960

Please sign in to comment.