Merge branch '145-if-the-cli-is-invoked-without-any-parameter-the-usage-is-shown-twice' into 'release/1.5.x'

Resolve "If the CLI is invoked without any parameter, the usage is shown twice"

See merge request kosit/validator!71
This commit is contained in:
Renzo Kottmann 2025-08-27 18:14:09 +02:00
commit d4d1aaea51
2 changed files with 11 additions and 4 deletions

View file

@ -25,7 +25,6 @@ import org.fusesource.jansi.AnsiRenderer.Code;
import de.kosit.validationtool.cmd.report.Line;
import de.kosit.validationtool.impl.Printer;
import picocli.CommandLine;
import picocli.CommandLine.ParseResult;
@ -79,11 +78,11 @@ public class CommandLineApplication {
final CommandLine commandLine = new CommandLine(new CommandLineOptions());
try {
commandLine.setExecutionExceptionHandler(CommandLineApplication::logExecutionException);
commandLine.execute(args);
if (commandLine.isUsageHelpRequested()) {
final int cmdlineRetVal = commandLine.execute(args);
if (commandLine.isUsageHelpRequested() || cmdlineRetVal == CommandLine.ExitCode.USAGE) {
resultStatus = ReturnValue.HELP_REQUEST;
} else {
resultStatus = ObjectUtils.defaultIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
resultStatus = ObjectUtils.getIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
if (resultStatus.isError()) {
commandLine.usage(System.out);
}

View file

@ -84,6 +84,14 @@ public class CommandlineApplicationTest {
assertThat(outputLines.stream().filter(l -> l.startsWith(CommandLineOptions.SYNOSIS_HEADING))).hasSize(1);
}
@Test
public void testNoArguments() {
final String[] args = {};
CommandLineApplication.mainProgram(args);
assertThat(CommandLine.getErrorOutput()).isNotEmpty();
checkForHelp(CommandLine.getErrorLines());
}
@Test
public void testRequiredScenarioFile() {
final String[] args = { "arguments", "egal welche", "argumente drin sind" };