Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/requirements/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
parent: Requirements
---
# CLI

## Unified `--input` option across all commands
`req~jabkit.cli.input-flag~1`

All `jabkit` commands that need a file input must have the `--input` option to specify the input file.
See [ADR 45](../decisions/0045-use-input-flag-always-for-input-files.md) for more details.

Needs: impl

<!-- markdownlint-disable-file MD022 -->
1 change: 1 addition & 0 deletions jabkit/src/main/java/org/jabref/cli/CheckConsistency.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CheckConsistency implements Callable<Integer> {
@Mixin
private ArgumentProcessor.SharedOptions sharedOptions = new ArgumentProcessor.SharedOptions();

// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input BibTeX file", required = true)
private Path inputFile;

Expand Down
5 changes: 3 additions & 2 deletions jabkit/src/main/java/org/jabref/cli/CheckIntegrity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static picocli.CommandLine.Command;
import static picocli.CommandLine.Mixin;
import static picocli.CommandLine.Option;
import static picocli.CommandLine.Parameters;

@Command(name = "check-integrity", description = "Check integrity of the database.")
class CheckIntegrity implements Callable<Integer> {
Expand All @@ -41,12 +40,14 @@ class CheckIntegrity implements Callable<Integer> {
@Mixin
private ArgumentProcessor.SharedOptions sharedOptions = new ArgumentProcessor.SharedOptions();

@Parameters(converter = CygWinPathConverter.class, description = "BibTeX file to check", arity = "1")
// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input BibTeX file", required = true)
private Path inputFile;

@Option(names = {"--output-format"}, description = "Output format: errorformat, txt or csv", defaultValue = "errorformat")
private String outputFormat;

// in BibTeX it could be preferences.getEntryEditorPreferences().shouldAllowIntegerEditionBibtex()
@Option(names = {"--allow-integer-edition"}, description = "Allows Integer edition: true or false", defaultValue = "true")
private boolean allowIntegerEdition = true;

Expand Down
1 change: 1 addition & 0 deletions jabkit/src/main/java/org/jabref/cli/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Convert implements Runnable {
@Mixin
private ArgumentProcessor.SharedOptions sharedOptions = new ArgumentProcessor.SharedOptions();

// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input file", required = true)
private Path inputFile;

Expand Down
6 changes: 4 additions & 2 deletions jabkit/src/main/java/org/jabref/cli/GenerateBibFromAux.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.jabref.cli.converter.CygWinPathConverter;
import org.jabref.logic.auxparser.AuxParser;
import org.jabref.logic.auxparser.AuxParserResult;
import org.jabref.logic.auxparser.AuxParserStatisticsProvider;
Expand Down Expand Up @@ -35,8 +36,9 @@ class GenerateBibFromAux implements Runnable {
@Option(names = "--aux", required = true)
private Path auxFile;

@Option(names = "--input", required = true)
private String inputFile;
// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input BibTeX file", required = true)
private Path inputFile;

@Option(names = "--output")
private Path outputFile;
Expand Down
6 changes: 4 additions & 2 deletions jabkit/src/main/java/org/jabref/cli/GenerateCitationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.jabref.cli.converter.CygWinPathConverter;
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
Expand All @@ -28,8 +29,9 @@ public class GenerateCitationKeys implements Runnable {
@Mixin
private ArgumentProcessor.SharedOptions sharedOptions = new ArgumentProcessor.SharedOptions();

@Option(names = "--input", description = "The input .bib file.", required = true)
private String inputFile;
// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input BibTeX file", required = true)
private Path inputFile;

@Option(names = "--output", description = "The output .bib file.")
private Path outputFile;
Expand Down
6 changes: 4 additions & 2 deletions jabkit/src/main/java/org/jabref/cli/PdfUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.jabref.cli.converter.CygWinPathConverter;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.exporter.EmbeddedBibFilePdfExporter;
Expand Down Expand Up @@ -49,8 +50,9 @@ class PdfUpdate implements Runnable {
@Option(names = {"-k", "--citation-key"}, description = "Citation keys", required = true)
private List<String> citationKeys = List.of(); // ToDo: check dedault value

@Option(names = "--input", description = "Input file", required = true)
private Path inputFile; // Local files only
// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input BibTeX file", required = true)
private Path inputFile;

@Option(names = "--input-format", description = "Input format of the file", required = true)
private String inputFormat = "*";
Expand Down
1 change: 1 addition & 0 deletions jabkit/src/main/java/org/jabref/cli/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Search implements Runnable {
@Option(names = {"--query"}, description = "Search query", required = true)
private String query;

// [impl->req~jabkit.cli.input-flag~1]
@Option(names = {"--input"}, converter = CygWinPathConverter.class, description = "Input BibTeX file", required = true)
private Path inputFile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ public Map<BibEntry, Range> getArticleRanges() {
}

public record Range(int startLine, int startColumn, int endLine, int endColumn) {
public static Range getNullRange() {
return new Range(0, 0, 0, 0);
}
public static final Range NULL_RANGE = new Range(0, 0, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class BibtexParser implements Parser {
private int line = 1;
private int column = 1;
// Stores the last read column of the highest column number encountered on any line so far.
// The intended data structure is Stack, but it is not used because Java code style checkers complain.
// In basic JDK data structures, there is no size-limited stack. We did not want to include Apache Commons Collections only for "CircularFifoBuffer"
private final Deque<Integer> highestColumns = new ArrayDeque<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class IntegrityCheckResultErrorFormatWriter extends IntegrityCheckResultWriter {

private final ParserResult parserResult;
private Path inputFile;
private final Path inputFile;

public IntegrityCheckResultErrorFormatWriter(Writer writer, List<IntegrityMessage> messages, ParserResult parserResult, Path inputFile) {
super(writer, messages);
Expand All @@ -26,9 +26,9 @@ public IntegrityCheckResultErrorFormatWriter(Writer writer, List<IntegrityMessag
public void writeFindings() throws IOException {
for (IntegrityMessage message : messages) {
Map<Field, ParserResult.Range> fieldRangeMap = parserResult.getFieldRanges().getOrDefault(message.entry(), new HashMap<>());
ParserResult.Range fieldRange = fieldRangeMap.getOrDefault(message.field(), fieldRangeMap.getOrDefault(InternalField.KEY_FIELD, parserResult.getArticleRanges().getOrDefault(message.entry(), ParserResult.Range.getNullRange())));
ParserResult.Range fieldRange = fieldRangeMap.getOrDefault(message.field(), fieldRangeMap.getOrDefault(InternalField.KEY_FIELD, parserResult.getArticleRanges().getOrDefault(message.entry(), ParserResult.Range.NULL_RANGE)));

System.out.printf("%s:%d:%d: %s\n".formatted(
writer.write("%s:%d:%d: %s\n".formatted(
inputFile,
fieldRange.startLine(),
fieldRange.startColumn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ public IntegrityCheckResultTxtWriter(Writer writer, List<IntegrityMessage> messa

@Override
public void writeFindings() throws IOException {
messages.forEach(System.out::println);
for (IntegrityMessage message : messages) {
writer.write(message.toString());
writer.write(System.lineSeparator());
}
}

@Override
public void close() throws IOException { }
public void close() throws IOException {
}
}
Loading