From 96a069ad7b725b7974a059838772ec47049f2a30 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 25 Mar 2025 01:21:15 +0200 Subject: [PATCH] Possibility to specify alternative configuration file for selftest command --- .../eu/svjatoslav/alyverkko_cli/AiTask.java | 2 +- .../eu/svjatoslav/alyverkko_cli/Main.java | 1 + .../commands/SelftestCommand.java | 24 ++++++++++++++++++- .../MailCorrespondentCommand.java | 2 +- .../{ => mail_correspondant}/MailQuery.java | 2 +- 5 files changed, 27 insertions(+), 4 deletions(-) rename src/main/java/eu/svjatoslav/alyverkko_cli/commands/{ => mail_correspondant}/MailCorrespondentCommand.java (99%) rename src/main/java/eu/svjatoslav/alyverkko_cli/commands/{ => mail_correspondant}/MailQuery.java (94%) diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java b/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java index 73c3ede..fa35763 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java @@ -1,6 +1,6 @@ package eu.svjatoslav.alyverkko_cli; -import eu.svjatoslav.alyverkko_cli.commands.MailQuery; +import eu.svjatoslav.alyverkko_cli.commands.mail_correspondant.MailQuery; import java.io.*; import java.nio.file.Files; diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java b/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java index f79f341..25fa1fd 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/Main.java @@ -1,6 +1,7 @@ package eu.svjatoslav.alyverkko_cli; import eu.svjatoslav.alyverkko_cli.commands.*; +import eu.svjatoslav.alyverkko_cli.commands.mail_correspondant.MailCorrespondentCommand; import eu.svjatoslav.alyverkko_cli.configuration.Configuration; import java.io.IOException; diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java index 3a7bd0f..cfe7a2e 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java @@ -3,6 +3,8 @@ package eu.svjatoslav.alyverkko_cli.commands; import eu.svjatoslav.alyverkko_cli.AiTask; import eu.svjatoslav.alyverkko_cli.Command; import eu.svjatoslav.alyverkko_cli.Main; +import eu.svjatoslav.commons.cli_helper.parameter_parser.Parser; +import eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileOption; import java.io.File; import java.io.IOException; @@ -25,6 +27,15 @@ public class SelftestCommand implements Command { return "selftest"; } + final Parser parser = new Parser(); + + /** + * Optional CLI argument for specifying a configuration file path. + */ + public FileOption configFileOption = parser.add(new FileOption("Configuration file path")) + .addAliases("--config", "-c") + .mustExist(); + /** * Executes the self-test, checking if various directories, files, and * configurations exist and are valid. @@ -37,7 +48,18 @@ public class SelftestCommand implements Command { // Perform selftest checks here System.out.println("Starting selftest..."); - configuration = loadConfiguration(); + if (!parser.parse(cliArguments)) { + System.out.println("Failed to parse commandline arguments"); + parser.showHelp(); + return; + } + + configuration = loadConfiguration(configFileOption.isPresent() ? configFileOption.getValue() : null); + if (configuration == null) { + System.out.println("Failed to load configuration file"); + return; + } + boolean didAllChecksPass = true; // Check if the configuration is loaded diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/MailCorrespondentCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java similarity index 99% rename from src/main/java/eu/svjatoslav/alyverkko_cli/commands/MailCorrespondentCommand.java rename to src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java index 32299dd..7bb24ee 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/MailCorrespondentCommand.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.alyverkko_cli.commands; +package eu.svjatoslav.alyverkko_cli.commands.mail_correspondant; import eu.svjatoslav.alyverkko_cli.*; import eu.svjatoslav.alyverkko_cli.model.Model; diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/MailQuery.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailQuery.java similarity index 94% rename from src/main/java/eu/svjatoslav/alyverkko_cli/commands/MailQuery.java rename to src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailQuery.java index f1a5627..a33584f 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/MailQuery.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailQuery.java @@ -1,4 +1,4 @@ -package eu.svjatoslav.alyverkko_cli.commands; +package eu.svjatoslav.alyverkko_cli.commands.mail_correspondant; import eu.svjatoslav.alyverkko_cli.model.Model; -- 2.20.1