mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
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:
commit
d4d1aaea51
2 changed files with 11 additions and 4 deletions
|
|
@ -25,7 +25,6 @@ import org.fusesource.jansi.AnsiRenderer.Code;
|
||||||
|
|
||||||
import de.kosit.validationtool.cmd.report.Line;
|
import de.kosit.validationtool.cmd.report.Line;
|
||||||
import de.kosit.validationtool.impl.Printer;
|
import de.kosit.validationtool.impl.Printer;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
import picocli.CommandLine.ParseResult;
|
import picocli.CommandLine.ParseResult;
|
||||||
|
|
||||||
|
|
@ -79,11 +78,11 @@ public class CommandLineApplication {
|
||||||
final CommandLine commandLine = new CommandLine(new CommandLineOptions());
|
final CommandLine commandLine = new CommandLine(new CommandLineOptions());
|
||||||
try {
|
try {
|
||||||
commandLine.setExecutionExceptionHandler(CommandLineApplication::logExecutionException);
|
commandLine.setExecutionExceptionHandler(CommandLineApplication::logExecutionException);
|
||||||
commandLine.execute(args);
|
final int cmdlineRetVal = commandLine.execute(args);
|
||||||
if (commandLine.isUsageHelpRequested()) {
|
if (commandLine.isUsageHelpRequested() || cmdlineRetVal == CommandLine.ExitCode.USAGE) {
|
||||||
resultStatus = ReturnValue.HELP_REQUEST;
|
resultStatus = ReturnValue.HELP_REQUEST;
|
||||||
} else {
|
} else {
|
||||||
resultStatus = ObjectUtils.defaultIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
|
resultStatus = ObjectUtils.getIfNull(commandLine.getExecutionResult(), ReturnValue.PARSING_ERROR);
|
||||||
if (resultStatus.isError()) {
|
if (resultStatus.isError()) {
|
||||||
commandLine.usage(System.out);
|
commandLine.usage(System.out);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,14 @@ public class CommandlineApplicationTest {
|
||||||
assertThat(outputLines.stream().filter(l -> l.startsWith(CommandLineOptions.SYNOSIS_HEADING))).hasSize(1);
|
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
|
@Test
|
||||||
public void testRequiredScenarioFile() {
|
public void testRequiredScenarioFile() {
|
||||||
final String[] args = { "arguments", "egal welche", "argumente drin sind" };
|
final String[] args = { "arguments", "egal welche", "argumente drin sind" };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue