[2973] fix "help {command}"
This commit is contained in:
parent
e4138d9341
commit
10f0b0877c
|
@ -282,7 +282,7 @@ public abstract class BaseApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<BaseCommand> parseCommand(String[] theArgs) {
|
private Optional<BaseCommand> parseCommand(String[] theArgs) {
|
||||||
Optional<BaseCommand> commandOpt = getNextCommand(theArgs);
|
Optional<BaseCommand> commandOpt = getNextCommand(theArgs, 0);
|
||||||
|
|
||||||
if (! commandOpt.isPresent()) {
|
if (! commandOpt.isPresent()) {
|
||||||
String message = "Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE);
|
String message = "Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE);
|
||||||
|
@ -294,8 +294,8 @@ public abstract class BaseApp {
|
||||||
return commandOpt;
|
return commandOpt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<BaseCommand> getNextCommand(String[] theArgs) {
|
private Optional<BaseCommand> getNextCommand(String[] theArgs, int thePosition) {
|
||||||
return ourCommands.stream().filter(cmd -> cmd.getCommandName().equals(theArgs[0])).findFirst();
|
return ourCommands.stream().filter(cmd -> cmd.getCommandName().equals(theArgs[thePosition])).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processHelp(String[] theArgs) {
|
private void processHelp(String[] theArgs) {
|
||||||
|
@ -303,7 +303,7 @@ public abstract class BaseApp {
|
||||||
logUsage();
|
logUsage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Optional<BaseCommand> commandOpt = getNextCommand(theArgs);
|
Optional<BaseCommand> commandOpt = getNextCommand(theArgs, 1);
|
||||||
if (! commandOpt.isPresent()) {
|
if (! commandOpt.isPresent()) {
|
||||||
String message = "Unknown command: " + theArgs[1];
|
String message = "Unknown command: " + theArgs[1];
|
||||||
System.err.println(message);
|
System.err.println(message);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package ca.uhn.fhir.cli;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
public class BaseAppTest {
|
||||||
|
|
||||||
|
private final PrintStream standardOut = System.out;
|
||||||
|
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
System.setOut(new PrintStream(outputStreamCaptor));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() {
|
||||||
|
System.setOut(standardOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHelpOption() {
|
||||||
|
App.main(new String[]{"help", "create-package"});
|
||||||
|
assertThat(outputStreamCaptor.toString().trim(), outputStreamCaptor.toString().trim(), containsString("Usage"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 2973
|
||||||
|
title: "CLI \"smileutil help {command}\" returns \"Unknown command\" which should return the usage of {command}. This has been corrected."
|
Loading…
Reference in New Issue