diff --git a/jabkit/src/main/java/org/jabref/toolkit/JabKitLauncher.java b/jabkit/src/main/java/org/jabref/toolkit/JabKitLauncher.java index 27d4457ba89..59c4b3c9a97 100644 --- a/jabkit/src/main/java/org/jabref/toolkit/JabKitLauncher.java +++ b/jabkit/src/main/java/org/jabref/toolkit/JabKitLauncher.java @@ -7,6 +7,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -104,26 +105,43 @@ public static void main(String[] args) { } } + /** + * Applies appropriate usage footers to each subcommand based on their supported options. + * Distinguishes between input formats, output formats, and export formats. + */ private static void applyUsageFooters(CommandLine commandLine, List> inputFormats, List> outputFormats, Set fetchers) { + + final String INPUT_FOOTER_LABEL = Localization.lang("Available import formats:"); + final String OUTPUT_FOOTER_LABEL = Localization.lang("Available output formats:"); + final String EXPORT_FOOTER_LABEL = Localization.lang("Available export formats:"); + String inputFooter = "\n" - + Localization.lang("Available import formats:") + "\n" + + INPUT_FOOTER_LABEL + "\n" + StringUtil.alignStringTable(inputFormats); String outputFooter = "\n" - + Localization.lang("Available export formats:") + "\n" + + OUTPUT_FOOTER_LABEL + "\n" + + StringUtil.alignStringTable(outputFormats); + String exportFooter = "\n" + + EXPORT_FOOTER_LABEL + "\n" + StringUtil.alignStringTable(outputFormats); commandLine.getSubcommands().values().forEach(subCommand -> { - boolean hasInputOption = subCommand.getCommandSpec().options().stream() - .anyMatch(opt -> Arrays.asList(opt.names()).contains("--input-format")); - boolean hasOutputOption = subCommand.getCommandSpec().options().stream() - .anyMatch(opt -> Arrays.asList(opt.names()).contains("--output-format")); + Map hasOptions = Map.of( + "input", hasCommandOption(subCommand.getCommandSpec(), "--input-format"), + "output", hasCommandOption(subCommand.getCommandSpec(), "--output-format"), + "export", hasCommandOption(subCommand.getCommandSpec(), "--export-format") + ); String footerText = ""; - footerText += hasInputOption ? inputFooter : ""; - footerText += hasOutputOption ? outputFooter : ""; + // Skip format footers for check-consistency since formats are already documented in option description + if (!"check-consistency".equals(subCommand.getCommandSpec().name())) { + footerText += hasOptions.get("input") ? inputFooter : ""; + footerText += hasOptions.get("output") ? outputFooter : ""; + footerText += hasOptions.get("export") ? exportFooter : ""; + } subCommand.getCommandSpec().usageMessage().footer(footerText); }); @@ -135,6 +153,11 @@ private static void applyUsageFooters(CommandLine commandLine, .collect(Collectors.joining(", "))); } + private static boolean hasCommandOption(CommandLine.Model.CommandSpec commandSpec, String optionName) { + return commandSpec.options().stream() + .anyMatch(opt -> Arrays.asList(opt.names()).contains(optionName)); + } + /// This needs to be called as early as possible. After the first log writing, it /// is not possible to alter the log configuration programmatically anymore. public static void initLogging(String[] args) { diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties index 8c94453fd4b..4d59ad2602b 100644 --- a/jablib/src/main/resources/l10n/JabRef_en.properties +++ b/jablib/src/main/resources/l10n/JabRef_en.properties @@ -3301,6 +3301,7 @@ Continue\ walkthrough=Continue walkthrough # CommandLine Available\ export\ formats\:=Available export formats: Available\ import\ formats\:=Available import formats: +Available\ output\ formats\:=Available output formats: Cannot\ embed\ metadata\ on\ any\ linked\ files\ of\ %s.\ Make\ sure\ there\ is\ at\ least\ one\ linked\ file\ and\ the\ path\ is\ correct.=Cannot embed metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct. Cannot\ write\ XMP\ metadata\ on\ any\ linked\ files\ of\ %0.\ Make\ sure\ there\ is\ at\ least\ one\ linked\ file\ and\ the\ path\ is\ correct.=Cannot write XMP metadata on any linked files of %0. Make sure there is at least one linked file and the path is correct. Checking\ consistency\ of\ '%0'.=Checking consistency of '%0'.