Search in sources :

Example 1 with Action

use of com.evolveum.midpoint.cli.seppuku.action.Action in project midpoint by Evolveum.

the class Main method start.

private void start(String[] args) {
    LOG.debug("Arguments: {}", Arrays.toString(args));
    DefaultCommand def = new DefaultCommand();
    JCommander commander = new JCommander(def);
    for (Map.Entry<String, ActionValue> entry : ACTIONS.entrySet()) {
        ActionValue value = entry.getValue();
        commander.addCommand(entry.getKey(), value.command);
    }
    commander.parse(args);
    String cmd = commander.getParsedCommand();
    LOG.debug("Parsed command: '{}'", cmd);
    if (StringUtils.isEmpty(cmd)) {
        if (def.isVersion()) {
            printVersion();
        }
        if (def.isHelp()) {
            printHelp(commander);
        }
        return;
    }
    ActionValue actionValue = null;
    for (Map.Entry<String, ActionValue> entry : ACTIONS.entrySet()) {
        if (cmd != null && cmd.equals(entry.getKey())) {
            actionValue = entry.getValue();
            break;
        }
    }
    if (actionValue == null) {
        printHelp(commander);
        return;
    }
    try {
        LOG.debug("Executing action {} with params {}", actionValue.action.getSimpleName(), actionValue.command);
        Action action = createAction(actionValue.action, actionValue.command, commander);
        action.execute();
    } catch (Exception ex) {
        handleError(ex);
    }
}
Also used : Action(com.evolveum.midpoint.cli.seppuku.action.Action) JCommander(com.beust.jcommander.JCommander) DefaultCommand(com.evolveum.midpoint.cli.common.DefaultCommand) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

JCommander (com.beust.jcommander.JCommander)1 DefaultCommand (com.evolveum.midpoint.cli.common.DefaultCommand)1 Action (com.evolveum.midpoint.cli.seppuku.action.Action)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1