Skip to content

Commit 4c9b19d

Browse files
committed
Fix the unit tests to not pollute the console with expected exception details.
1 parent 2202c8c commit 4c9b19d

File tree

2 files changed

+96
-77
lines changed

2 files changed

+96
-77
lines changed

tools/bamm-cli/src/main/java/io/openmanufacturing/sds/BammCli.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,29 @@ public class BammCli extends AbstractCommand {
3232

3333
public static final String COMMAND_NAME = "bamm";
3434

35-
private final CommandLine commandLine = new CommandLine( this );
35+
private final CommandLine commandLine = new CommandLine( this )
36+
.addSubcommand( new AspectCommand() )
37+
.setCaseInsensitiveEnumValuesAllowed( true );
3638

37-
public void run( final String... argv ) throws Exception {
38-
main( argv );
39+
int run( final String... argv ) {
40+
return commandLine.execute( argv );
3941
}
4042

41-
public static void main( final String[] argv ) throws Exception {
43+
int runWithExceptionHandler( final CommandLine.IExecutionExceptionHandler exceptionHandler, final String... argv ) {
44+
final CommandLine.IExecutionExceptionHandler oldHandler = commandLine.getExecutionExceptionHandler();
45+
try {
46+
commandLine.setExecutionExceptionHandler( exceptionHandler );
47+
return commandLine.execute( argv );
48+
} finally {
49+
commandLine.setExecutionExceptionHandler( oldHandler );
50+
}
51+
}
52+
53+
public static void main( final String[] argv ) {
4254
AnsiConsole.systemInstall();
4355

4456
final BammCli command = new BammCli();
45-
final CommandLine commandLine = command.commandLine
46-
.addSubcommand( new AspectCommand() )
47-
.setCaseInsensitiveEnumValuesAllowed( true );
48-
49-
final int exitCode = commandLine.execute( argv );
57+
final int exitCode = command.commandLine.execute( argv );
5058
AnsiConsole.systemUninstall();
5159
System.exit( exitCode );
5260
}

0 commit comments

Comments
 (0)