Skip to content
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

CLI: Make help output consistent: import and export formats #9937

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue in the preferences 'External file types' tab ignoring a custom application path in the edit dialog. [#9895](https://github.com/JabRef/jabref/issues/9895)
- We fixed an issue in the preferences where custom columns could be added to the entry table with no qualifier. [#9913](https://github.com/JabRef/jabref/issues/9913)
- We fixed an issue where the encoding header in a bib file was not respected when the file contained a BOM (Byte Order Mark). [#9926](https://github.com/JabRef/jabref/issues/9926)
- We fixed the issue where cli output import and export format inconsistent. [koppor#429](https://github.com/koppor/jabref/issues/429)

### Removed

Expand Down
25 changes: 22 additions & 3 deletions src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

Expand Down Expand Up @@ -161,7 +162,7 @@ public boolean isWriteMetadatatoPdf() {
public String getWriteMetadatatoPdf() {
return cl.hasOption("writeMetadatatoPdf") ? cl.getOptionValue("writeMetadatatoPdf") :
cl.hasOption("writeXMPtoPdf") ? cl.getOptionValue("writeXMPtoPdf") :
cl.hasOption("embeddBibfileInPdf") ? cl.getOptionValue("embeddBibfileInPdf") : null;
cl.hasOption("embeddBibfileInPdf") ? cl.getOptionValue("embeddBibfileInPdf") : null;
}

private static Options getOptions() {
Expand Down Expand Up @@ -304,8 +305,8 @@ public static void printUsage(PreferencesService preferencesService) {
Globals.entryTypesManager,
Globals.journalAbbreviationRepository);
String outFormatsIntro = Localization.lang("Available export formats");
String outFormats = wrapStringList(exporterFactory.getExporters().stream().map(Exporter::getId).toList(), outFormatsIntro.length());
String outFormatsList = String.format("%s: %s%n", outFormatsIntro, outFormats);
String outFormats = getExportFormatList(exporterFactory.getExporters());
String outFormatsList = String.format("%s:%n%s%n", outFormatsIntro, outFormats);

String footer = '\n' + importFormatsList + outFormatsList + "\nPlease report issues at https://github.com/JabRef/jabref/issues.";

Expand All @@ -321,6 +322,24 @@ public List<String> getLeftOver() {
return leftOver;
}

protected static String getExportFormatList(List<Exporter> exporters) {
StringBuilder sb = new StringBuilder();

for (Exporter exporter : exporters) {
int pad = Math.max(0, 14 - exporter.getName().length());
sb.append(" ");
sb.append(exporter.getName());

sb.append(StringUtil.repeatSpaces(pad));

sb.append(" : ");
sb.append(exporter.getId());
sb.append('\n');
}

return sb.toString();
}

/**
* Creates and wraps a multi-line and colon-seperated string from a List of Strings.
*/
Expand Down