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

Renamed the result-directory option to result-file #1566

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 17 additions & 5 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public final class CLI {

private static final String DESCRIPTION_PATTERN = "%nJPlag - %s%n%s%n%n";

private static final String DEFAULT_FILE_ENDING = ".zip";

/**
* Main class for using JPlag via the CLI.
* @param args are the CLI arguments that will be passed to JPlag.
Expand All @@ -79,10 +81,10 @@ public static void main(String[] args) {
if (!parseResult.isUsageHelpRequested() && !(parseResult.subcommand() != null && parseResult.subcommand().isUsageHelpRequested())) {
JPlagOptions options = cli.buildOptionsFromArguments(parseResult);
JPlagResult result = JPlag.run(options);
ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File(cli.getResultFolder() + ".zip"));
ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File(cli.getResultFilePath()));
reportObjectFactory.createAndSaveReport(result);

OutputFileGenerator.generateCsvOutput(result, new File(cli.getResultFolder()), cli.options);
OutputFileGenerator.generateCsvOutput(result, new File(cli.getResultFileBaseName()), cli.options);
}
} catch (ExitException | FileNotFoundException exception) {
logger.error(exception.getMessage()); // do not pass exception here to keep log clean
Expand Down Expand Up @@ -144,7 +146,7 @@ public ParseResult parseOptions(String... args) throws CliException {
}
return result;
} catch (CommandLine.ParameterException e) {
if (e.getArgSpec().isOption() && Arrays.asList(((OptionSpec) e.getArgSpec()).names()).contains("-l")) {
if (e.getArgSpec() != null && e.getArgSpec().isOption() && Arrays.asList(((OptionSpec) e.getArgSpec()).names()).contains("-l")) {
throw new CliException(String.format(UNKOWN_LANGAUGE_EXCEPTION, e.getValue(),
String.join(", ", LanguageLoader.getAllAvailableLanguageIdentifiers())));
}
Expand Down Expand Up @@ -250,7 +252,17 @@ private String generateDescription() {
return String.format(DESCRIPTION_PATTERN, randomDescription, CREDITS);
}

public String getResultFolder() {
return this.options.resultFolder;
private String getResultFilePath() {
String optionValue = this.options.resultFile;
if (optionValue.endsWith(DEFAULT_FILE_ENDING)) {
return optionValue;
} else {
return optionValue + DEFAULT_FILE_ENDING;
}
}

private String getResultFileBaseName() {
String defaultOutputFile = getResultFilePath();
return defaultOutputFile.substring(0, defaultOutputFile.length() - DEFAULT_FILE_ENDING.length());
}
tsaglam marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class CliOptions implements Runnable {
public int shownComparisons = JPlagOptions.DEFAULT_SHOWN_COMPARISONS;

@Option(names = {"-r",
"--result-directory"}, description = "Name of the directory in which the comparison results will be stored (default: ${DEFAULT-VALUE})%n")
public String resultFolder = "results";
"--result-file"}, description = "Name of the file in which the comparison results will be stored (default: ${DEFAULT-VALUE}). Missing .zip endings will be automatically added.%n")
public String resultFile = "results";

@ArgGroup(heading = "Advanced%n", exclusive = false)
public Advanced advanced = new Advanced();
Expand Down