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

Make sure unrecognized CLI command message is printed #11357

Merged
merged 1 commit into from
Oct 18, 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
3 changes: 2 additions & 1 deletion engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private static Options buildOptions() {
}

/** Prints the help message to the standard output. */
private static void printHelp() {
void printHelp() {
new HelpFormatter().printHelp(LanguageInfo.ID, CLI_OPTIONS);
}

Expand Down Expand Up @@ -1435,6 +1435,7 @@ final CommandLine preprocessArguments(String... args) {
System.currentTimeMillis() - startParsing);
return line;
} catch (Exception e) {
println(e.getMessage());
printHelp();
throw exitFail();
}
Expand Down
23 changes: 23 additions & 0 deletions engine/runner/src/test/java/org/enso/runner/EngineMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -17,6 +18,21 @@ public class EngineMainTest {

private final List<String> linesOut = new ArrayList<>();

@Test
public void unknownCommandBecauseTwoAreConcatenated() throws Exception {
var m = new MainMock();
try {
var file = tempDir.newFile("some.enso");
var line = m.preprocessArguments("--repl --inspect", "--run", file.getAbsolutePath());
m.mainEntry(line, Level.INFO, false);
} catch (ExitCode ex) {
assertEquals("Execution fails", 1, ex.exitCode);
assertEquals("One line printed", 1, linesOut.size());
assertEquals("Unrecognized option: --repl --inspect", linesOut.get(0));
assertTrue("Also help was printed", m.helpPrinted);
}
}

@Test
public void cannotUseReplAndInspectAtOnce() throws Exception {
try {
Expand Down Expand Up @@ -76,6 +92,8 @@ public void systemPropertyArgumentIncorrectFormat() throws IOException {
}

private final class MainMock extends Main {
boolean helpPrinted;

@Override
RuntimeException doExit(int exitCode) {
throw new ExitCode(exitCode);
Expand All @@ -85,6 +103,11 @@ RuntimeException doExit(int exitCode) {
void println(String msg) {
linesOut.add(msg);
}

@Override
void printHelp() {
helpPrinted = true;
}
}

private static final class ExitCode extends RuntimeException {
Expand Down
Loading