Feat: CLI Support for Field Formatters in Export Commands#15184
Conversation
Review Summary by QodoAdd CLI field formatters support to export commands
WalkthroughsDescription• Add --field-formatters CLI option to convert and generate-bib-from-aux commands • Enable field formatter application during export without GUI interaction • Support comma-separated formatter list with field-specific cleanup operations • Include comprehensive test coverage for formatter application during conversion Diagramflowchart LR
CLI["CLI Arguments<br/>--field-formatters"]
Parser["Parse Formatters<br/>FieldFormatterCleanupMapper"]
Convert["Convert/GenerateBibFromAux<br/>Commands"]
Apply["Apply Cleanup<br/>to BibEntries"]
Output["Export Clean<br/>Bibliography"]
CLI -- "comma-separated list" --> Parser
Parser -- "FieldFormatterCleanup objects" --> Convert
Convert -- "iterate entries" --> Apply
Apply -- "formatted entries" --> Output
File Changes1. jabkit/src/main/java/org/jabref/toolkit/commands/Convert.java
|
Code Review by Qodo
1.
|
| if (fieldFormatters != null && !fieldFormatters.isBlank()) { | ||
| String parseableString = fieldFormatters.replace(",", "\n"); | ||
| List<FieldFormatterCleanup> cleanups = FieldFormatterCleanupMapper.parseActions(parseableString); | ||
| for (BibEntry entry : parserResult.get().getDatabase().getEntries()) { |
There was a problem hiding this comment.
1. convert formatter parsing broken 📘 Rule violation ✓ Correctness
The new --field-formatters parsing replaces all commas, which breaks specifying multiple formatters within a single field (commas inside [...]). This can silently apply the wrong formatter(s) or none at all, producing incorrect export output.
Agent Prompt
## Issue description
`--field-formatters` currently does `fieldFormatters.replace(",", "\n")`, which corrupts valid formatter specs that contain comma-separated formatter lists inside brackets (e.g., `title[escapeAmpersands,latex_cleanup]`). This can lead to silently wrong/no cleanup actions.
## Issue Context
This CLI argument is external input and should be parsed robustly. The current approach cannot distinguish commas separating field blocks from commas separating formatters within a field.
## Fix Focus Areas
- jabkit/src/main/java/org/jabref/toolkit/commands/Convert.java[72-80]
- jabkit/src/main/java/org/jabref/toolkit/commands/GenerateBibFromAux.java[86-94]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This comment has been minimized.
This comment has been minimized.
|
Your pull request conflicts with the target branch. Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line. |
|
I feel like in the parsing logic using replace("," , "\n") might accidentally break formatters that contain internal commas. Since you are already using FieldFormatterCleanupMapper you could use a more robust regex split or split only on top level commas (ignoring commas inside brackets). |
Yes I identified it, and working on that. |
…ar/jabref into clean-cli-feature
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ All tests passed ✅🏷️ Commit: cd57114 Learn more about TestLens at testlens.app. |
* Add CLI support for field formatters in export commands * update CHANGELOG.md * update CHANGELOG.md * fix CHANGELOG.md * fix CHANGELOG.md * new modifications * removed unused imports * Consistency in test class * move static method to common util class, simplified regex --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> Co-authored-by: Carl Christian Snethlage <calixtus@users.noreply.github.com>
* Add CLI support for field formatters in export commands * update CHANGELOG.md * update CHANGELOG.md * fix CHANGELOG.md * fix CHANGELOG.md * new modifications * removed unused imports * Consistency in test class * move static method to common util class, simplified regex --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> Co-authored-by: Carl Christian Snethlage <calixtus@users.noreply.github.com>
* Add CLI support for field formatters in export commands * update CHANGELOG.md * update CHANGELOG.md * fix CHANGELOG.md * fix CHANGELOG.md * new modifications * removed unused imports * Consistency in test class * move static method to common util class, simplified regex --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Co-authored-by: Christoph <siedlerkiller@gmail.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> Co-authored-by: Carl Christian Snethlage <calixtus@users.noreply.github.com>
Related issues and pull requests
Closes #11520
PR Description
This PR adds a
--field-formattersoption to theconvertandgenerate-bib-from-auxCLI commands.It lets users run JabRef's field formatters (like cleaning up dates, fixing page numbers, or clearing comments) directly from the command line when exporting files. This is really useful for users who want to clean up their .bib files for publication without having to open the GUI or permanently change their main database. It works by passing a comma-separated list of formatters directly to the existing cleanup logic.
Steps to test
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)