Skip to content

Commit

Permalink
🦄 refactor: Add JaspilerMain.internalMain()
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Jun 29, 2023
1 parent 16e875a commit ec767a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/caoccao/jaspiler/JaspilerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
description = JaspilerContract.DESCRIPTION)
public final class JaspilerMain extends BaseLoggingObject implements Callable<Integer> {
@CommandLine.Parameters(hidden = true)
private List<String> argv;
private final List<String> argv;
@CommandLine.Parameters(index = "0", description = "The JavaScript file to be executed.")
private File file;

Expand All @@ -47,8 +47,12 @@ public JaspilerMain() {
file = null;
}

public static int internalMain(String[] args) {
return new CommandLine(new JaspilerMain()).execute(args);
}

public static void main(String[] args) {
System.exit(new CommandLine(new JaspilerMain()).execute(args));
System.exit(internalMain(args));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/caoccao/jaspiler/TestJaspilerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testArgv() throws Exception {
String scriptPath = SystemUtils.INITIAL_WORKING_DIRECTORY.resolve("scripts/node/test/test_argv.js")
.toAbsolutePath().toFile().getAbsolutePath();
List<String> args = List.of(scriptPath, "a", "b", "c");
assertEquals(0, new CommandLine(new JaspilerMain()).execute(args.toArray(String[]::new)));
assertEquals(0, JaspilerMain.internalMain(args.toArray(String[]::new)));
}

@Test
Expand Down

0 comments on commit ec767a4

Please sign in to comment.