Search in sources :

Example 1 with DefaultCommand

use of com.evolveum.midpoint.cli.common.DefaultCommand 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)

Example 2 with DefaultCommand

use of com.evolveum.midpoint.cli.common.DefaultCommand 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 : 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)2 DefaultCommand (com.evolveum.midpoint.cli.common.DefaultCommand)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Action (com.evolveum.midpoint.cli.seppuku.action.Action)1