use of org.ovirt.engine.core.uutils.cli.parser.ArgumentsParser in project ovirt-engine by oVirt.
the class LoggerServiceImpl method parseArguments.
@Override
public void parseArguments(List<String> args) throws Exception {
args.remove(0);
Properties props = new Properties();
try (InputStream in = LoggerServiceImpl.class.getResourceAsStream("arguments.properties");
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
props.load(reader);
}
Map<String, String> substitutions = context.get(ContextKeys.CLI_PARSER_SUBSTITUTIONS);
ArgumentsParser parser = new ArgumentsParser(props, "module");
parser.getSubstitutions().putAll(substitutions);
parser.parse(args);
argModuleMap = parser.getParsedArgs();
if ((Boolean) argModuleMap.get("help")) {
System.out.format("Usage: %s", parser.getUsage());
throw new ExitException("Help", 0);
}
if (!parser.getErrors().isEmpty()) {
for (Throwable t : parser.getErrors()) {
log.error(t.getMessage());
}
throw new ExitException("Parsing error", 1);
}
if (args.size() < 1) {
log.error("Action not provided");
throw new ExitException("Action not provided", 1);
}
try {
action = Action.valueOf(args.get(0).toUpperCase().replace("-", "_"));
} catch (IllegalArgumentException e) {
log.error("Invalid action '{}'", args.get(0));
throw new ExitException("Invalid action", 1);
}
argMap = action.parse(substitutions, props, args);
}
Aggregations