use of picocli.CommandLine.RunLast in project besu by hyperledger.
the class CommandLineUtilsTest method optionIsNotExpected.
@Test
public void optionIsNotExpected() {
final AbstractTestCommand testCommand = new TestCommandWithDeps(mockLogger);
testCommand.commandLine.parseWithHandlers(new RunLast(), defaultExceptionHandler(), "--option-enabled", "false", "--option2", "20", "--option4", "40");
verifyOptionsConstraintLoggerCall(mockLogger, "--option2", "--option-enabled");
assertThat(testCommand.optionEnabled).isFalse();
assertThat(testCommand.option2).isEqualTo(20);
assertThat(testCommand.option3).isEqualTo(3);
assertThat(testCommand.option4).isEqualTo(40);
}
use of picocli.CommandLine.RunLast in project besu by hyperledger.
the class CommandTestAbstract method parseCommand.
protected TestBesuCommand parseCommand(final InputStream in, final String... args) {
// turn off ansi usage globally in picocli
System.setProperty("picocli.ansi", "false");
final TestBesuCommand besuCommand = new TestBesuCommand(mockLogger, () -> rlpBlockImporter, this::jsonBlockImporterFactory, (blockchain) -> rlpBlockExporter, mockRunnerBuilder, mockControllerBuilderFactory, mockBesuPluginContext, environment, storageService, securityModuleService, mockPkiBlockCreationConfigProvider, privacyPluginService);
besuCommands.add(besuCommand);
File defaultKeyFile = KeyPairUtil.getDefaultKeyFile(DefaultCommandValues.getDefaultBesuDataPath(besuCommand));
try {
Files.writeString(defaultKeyFile.toPath(), keyPair.getPrivateKey().toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
besuCommand.setBesuConfiguration(commonPluginConfiguration);
// parse using Ansi.OFF to be able to assert on non formatted output results
besuCommand.parse(new RunLast().useOut(outPrintStream).useAnsi(Ansi.OFF), besuCommand.exceptionHandler().useErr(errPrintStream).useAnsi(Ansi.OFF), in, args);
return besuCommand;
}
use of picocli.CommandLine.RunLast in project ozone by apache.
the class TestOzoneDatanodeShell method executeDatanode.
private void executeDatanode(HddsDatanodeService hdds, String[] args) {
LOG.info("Executing datanode command with args {}", Arrays.asList(args));
CommandLine cmd = hdds.getCmd();
IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {
@Override
public List<Object> handleParseException(ParameterException ex, String[] args) {
throw ex;
}
@Override
public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseResult) {
throw ex;
}
};
cmd.parseWithHandlers(new RunLast(), exceptionHandler, args);
}
use of picocli.CommandLine.RunLast in project mixcr by milaboratory.
the class Main method handleParseResult.
public static void handleParseResult(ParseResult parseResult, String[] args) {
ExceptionHandler<Object> exHandler = new ExceptionHandler<>();
exHandler.andExit(1);
RunLast runLast = new RunLast() {
@Override
protected List<Object> handle(ParseResult parseResult) throws CommandLine.ExecutionException {
List<CommandLine> parsedCommands = parseResult.asCommandLineList();
CommandLine commandLine = parsedCommands.get(parsedCommands.size() - 1);
Object command = commandLine.getCommand();
try {
if (command instanceof CommandSpec && ((CommandSpec) command).userObject() instanceof Runnable) {
((Runnable) ((CommandSpec) command).userObject()).run();
return new ArrayList<>();
}
return super.handle(parseResult);
} catch (ParameterException ex) {
throw ex;
} catch (CommandLine.ExecutionException ex) {
throw ex;
} catch (Exception ex) {
throw new CommandLine.ExecutionException(commandLine, "Error while running command (" + command + "): " + ex, ex);
}
}
};
try {
runLast.handleParseResult(parseResult);
} catch (ParameterException ex) {
exHandler.handleParseException(ex, args);
} catch (CommandLine.ExecutionException ex) {
exHandler.handleExecutionException(ex, parseResult);
}
}
use of picocli.CommandLine.RunLast in project ozone by apache.
the class TestOzoneShellHA method execute.
private void execute(GenericCli shell, String[] args) {
LOG.info("Executing OzoneShell command with args {}", Arrays.asList(args));
CommandLine cmd = shell.getCmd();
IExceptionHandler2<List<Object>> exceptionHandler = new IExceptionHandler2<List<Object>>() {
@Override
public List<Object> handleParseException(ParameterException ex, String[] args) {
throw ex;
}
@Override
public List<Object> handleExecutionException(ExecutionException ex, ParseResult parseRes) {
throw ex;
}
};
// Since there is no elegant way to pass Ozone config to the shell,
// the idea is to use 'set' to place those OM HA configs.
String[] argsWithHAConf = getHASetConfStrings(args);
cmd.parseWithHandlers(new RunLast(), exceptionHandler, argsWithHAConf);
}
Aggregations