Skip to content

Feature/14361 enable parameters for cli#14500

Merged
calixtus merged 28 commits intoJabRef:mainfrom
CodeRishiX:feature/14361-enable-parameters-for-cli
Dec 21, 2025
Merged

Feature/14361 enable parameters for cli#14500
calixtus merged 28 commits intoJabRef:mainfrom
CodeRishiX:feature/14361-enable-parameters-for-cli

Conversation

@CodeRishiX
Copy link
Copy Markdown
Contributor

@CodeRishiX CodeRishiX commented Dec 3, 2025

Closes #14361

Added customizable parameters to JabKit's citationkeys generate command. Users can now configure citation key generation settings via CLI parameters, matching the customization options available in the JabRef GUI.

Implemented all CitationKeyPatternPreferences options as CLI parameters.

Steps to test

  1. Verify CLI options:
    ./gradlew :jabkit:run --args="citationkeys generate --help"
    

output :
Shows all citation key options
Confirms subcommand hierarchy

image
  1. Verify functionality:
    ./gradlew :jabkit:run --args="citationkeys generate --input=C:/git-repositories/jabref/jablib/src/main/resources/Chocolate.bib --pattern='[author][year]' --transliterate --warn-before-overwrite --suffix=ALWAYS --regex='[^a-zA-Z0-9]' --regex-replacement='' --keyword-delimiter='_'"
    
image image

No GUI settings are modified — this only affects the current CLI run

Mandatory checks

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 3, 2025
@Option(names = "--output", description = "The output .bib file.")
private Path outputFile;

@Option(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement as a subcommand. We need to keep some hierarchy to keep JabRef and all of its features manageable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks for suggesting .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calixtus
Thanks again for the guidance. I followed your suggestion and tried to update the hierarchy accordingly. Could you please check if it looks correct now and let me know if I should adjust anything before I continue adding the remaining parts?​

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeRishiX Did you update the screenshot in the PR description?

README.md Outdated
@@ -1,4 +1,4 @@
# JabRef Bibliography Management [![APIdia](https://apidia.net/java/JabRef/main/badge.svg)](https://apidia.net/java/JabRef/main)
# JabRef Bibliography Management [![APIdia](https://apidia.net/java/JabRef/main/badge.svg)](https://apidia.net/java/JabRef/main)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated to your PR. Please undo.

CitationKeyGenerator keyGenerator = new CitationKeyGenerator(
databaseContext,
argumentProcessor.cliPreferences.getCitationKeyPatternPreferences());
prefs);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use abbreviations.

System.out.println(Localization.lang("Regenerating citation keys according to metadata."));
}

var prefs = argumentProcessor.cliPreferences.getCitationKeyPatternPreferences();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use abbreviations.

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 4, 2025

For any inquiries, feel free to [contact ProductMap.ai](https://product-map.ai).

<!-- markdownlint-disable-file MD060 -->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Command(
name = "citationkeys",
description = "Manage citation key operations.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this is not a good text. Maybe just remove it.

test.bib Outdated
@@ -0,0 +1,12 @@
@article{dummy,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use src/main/resources/Chocolate.bib instead of putting a .bib file in the root of the repository.

@koppor koppor added the status: changes-required Pull requests that are not yet complete label Dec 4, 2025
@CodeRishiX
Copy link
Copy Markdown
Contributor Author

CodeRishiX commented Dec 6, 2025

@koppor @calixtus Fixed all review comments as suggested - removed CitationKeyCommands description, deleted test.bib, and resolved README changes.

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 6, 2025
Copy link
Copy Markdown
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments; I don't know What is left todo - the PR is flagged as "draft"


@Override
public void run() {
System.out.println("Testing");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates that the PR is sitll draft

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 7, 2025
@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 7, 2025

Not fully optimized yet.

Please work on this. See the screenshot at #14361.

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 9, 2025
@CodeRishiX
Copy link
Copy Markdown
Contributor Author

@calixtus @koppor
Hi!
I’ve implemented all parameters of CitationKeyPatternPreferences in the CLI except the per-entry-type patterns.

CitationKeyPatternPreferences supports type-specific patterns , but JabKit’s GlobalCitationKeyPatterns currently applies only a single default pattern and does not support per-entry-type overrides.

public class GlobalCitationKeyPatterns extends AbstractCitationKeyPatterns {

public GlobalCitationKeyPatterns(CitationKeyPattern defaultPattern) {
    this.defaultPattern = defaultPattern;
}

public static GlobalCitationKeyPatterns fromPattern(String pattern) {
    return new GlobalCitationKeyPatterns(new CitationKeyPattern(pattern));
}

@Override
public CitationKeyPattern getLastLevelCitationKeyPattern(EntryType entryType) {
    return defaultPattern;
}

Because of this mismatch, I’ve kept keyPatterns unchanged for now until your guidance.

Thanks!

DoiToBibtex.class,
Fetch.class,
GenerateBibFromAux.class,
GenerateCitationKeys.class,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be noted in "Removed" in CHANGELOG.md

@CodeRishiX
Copy link
Copy Markdown
Contributor Author

I wonder why there is not any banner displayed?

Hi @calixtus I’m not fully sure what you mean by the missing banner here. Do you expect the standard JabKit startup banner to be shown for citationkeys generate, or some explicit output indicating that the command is running/completed? Just want to confirm before implementing. Thanks!

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 18, 2025
@koppor koppor mentioned this pull request Dec 19, 2025
1 task
@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 19, 2025

I wonder why there is not any banner displayed?

No banner is OK --> #14664

koppor
koppor previously requested changes Dec 19, 2025
CHANGELOG.md Outdated

### Removed

- We removed `generate-citation-keys` as a standalone command in JabKit. Use `citationkeys generate` instead. [#14361](https://github.com/JabRef/jabref/issues/14361)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link the PR here, because it is not in the issue.

@Option(names = "--output", description = "The output .bib file.")
private Path outputFile;

@Option(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeRishiX Did you update the screenshot in the PR description?

avoidOverwrite != null ? avoidOverwrite : existingPreferences.shouldAvoidOverwriteCiteKey(),
warnBeforeOverwrite != null ? warnBeforeOverwrite : existingPreferences.shouldWarnBeforeOverwriteCiteKey(),
generateBeforeSaving != null ? generateBeforeSaving : existingPreferences.shouldGenerateCiteKeysBeforeSaving(),
suffix != null ? suffix : existingPreferences.getKeySuffix(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep key -- variable should be keySuffix. See other lines. They are consistent (somehow)

transliterate != null ? transliterate : existingPreferences.shouldTransliterateFieldsForCitationKey(),
avoidOverwrite != null ? avoidOverwrite : existingPreferences.shouldAvoidOverwriteCiteKey(),
warnBeforeOverwrite != null ? warnBeforeOverwrite : existingPreferences.shouldWarnBeforeOverwriteCiteKey(),
generateBeforeSaving != null ? generateBeforeSaving : existingPreferences.shouldGenerateCiteKeysBeforeSaving(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be consistent left and right.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 19, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 20, 2025
Copy link
Copy Markdown
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grafik

Minor tweaks to codestyle and handling of command with no subcommand.

@calixtus calixtus enabled auto-merge December 21, 2025 21:57
@calixtus calixtus added this pull request to the merge queue Dec 21, 2025
Merged via the queue into JabRef:main with commit 6671728 Dec 21, 2025
49 checks passed
keyPatternRegex != null ? keyPatternRegex : existingPreferences.getKeyPatternRegex(),
keyPatternReplacement != null ? keyPatternReplacement : existingPreferences.getKeyPatternReplacement(),
unwantedCharacters != null ? unwantedCharacters : existingPreferences.getUnwantedCharacters(),
existingPreferences.getKeyPatterns(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct?

Copy link
Copy Markdown
Member

@calixtus calixtus Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks correct to me. keypatterns cannot be overridden in the commandline. would be a funny commandline.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks correct to me. keypatterns cannot be overridden in the commandline. would be a funny commandline.

But it was wished in the issue

Offer each element of CitationKeyPatternPreferences as parameter in the CLI for org.jabref.toolkit.commands.GenerateCitationKeys

Reason: Use on server-side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks correct to me. keypatterns cannot be overridden in the commandline. would be a funny commandline.

But it was wished in the issue

Offer each element of CitationKeyPatternPreferences as parameter in the CLI for org.jabref.toolkit.commands.GenerateCitationKeys

Reason: Use on server-side.

@koppor I agree , maybe this matches the limitation I mentioned in my comment two weeks ago about keyPatterns and GlobalCitationKeyPatterns,

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks correct to me. keypatterns cannot be overridden in the commandline. would be a funny commandline.

But it was wished in the issue

Offer each element of CitationKeyPatternPreferences as parameter in the CLI for org.jabref.toolkit.commands.GenerateCitationKeys

Reason: Use on server-side.

@koppor I agree , maybe this matches the limitation I mentioned in my comment two weeks ago about keyPatterns and GlobalCitationKeyPatterns,

The next contributor will have to think of this. If we dive that deep, we could solve the issue for ourselves. We could then leave out humans and just use AI agents. (And believe me, we are short before doing this 😅).

transliterate != null ? transliterate : existingPreferences.shouldTransliterateFieldsForCitationKey(),
avoidOverwrite != null ? avoidOverwrite : existingPreferences.shouldAvoidOverwriteCiteKey(),
warnBeforeOverwrite != null ? warnBeforeOverwrite : existingPreferences.shouldWarnBeforeOverwriteCiteKey(),
generateBeforeSaving != null ? generateBeforeSaving : existingPreferences.shouldGenerateCiteKeysBeforeSaving(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming is still inconsistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: citationkey-generator component: JabKit [cli] good first issue An issue intended for project-newcomers. Varies in difficulty.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable parameters for CLI: generate-citation-keys

4 participants