Search in sources :

Example 1 with Commander

use of com.fo0.robot.commander.Commander in project Robot by fo0.

the class ChainActionItem method simple_commandline.

public EChainResponse simple_commandline(List<KeyValue> list) throws Exception {
    List<KeyValue> cmdList = list;
    // @formatter:off
    KeyValue HOME = ActionUtils.parseAction(cmdList, CONSTANTS_PATTERN.HOME, System.getProperty("user.dir"));
    KeyValue CMD = ActionUtils.parseAction(cmdList, CONSTANTS_PATTERN.CMD, cmdList.stream().map(KeyValue::getValue).findFirst().orElse(null));
    // @formatter:on
    ctx.addToLog(type, "HOME: " + HOME.getValue());
    ctx.addToLog(type, "CMD: " + CMD.getValue());
    Commander commander = new Commander(log -> {
        ctx.addToLogPlain(type, log);
    });
    commander.execute(true, true, HOME.getValue(), CMD.getValue());
    if (commander == null || commander.isError()) {
        ctx.addToLog(type, "error at commander: " + CMD.getKey());
        return EChainResponse.Failed;
    }
    return EChainResponse.Continue;
}
Also used : KeyValue(com.fo0.robot.model.KeyValue) Commander(com.fo0.robot.commander.Commander)

Example 2 with Commander

use of com.fo0.robot.commander.Commander in project Robot by fo0.

the class ChainActionItem method commandline.

public EChainResponse commandline(List<KeyValue> list) throws Exception {
    List<KeyValue> cmdList = list;
    // @formatter:off
    KeyValue WAIT = ActionUtils.parseAction(cmdList, CONSTANTS_PATTERN.WAIT, "true");
    KeyValue HOME = ActionUtils.parseAction(cmdList, CONSTANTS_PATTERN.HOME, System.getProperty("user.dir"));
    KeyValue CMDS = ActionUtils.parseAction(cmdList, CONSTANTS_PATTERN.CMDS, null);
    // formatter:on
    ctx.addToLog(type, "WAIT: " + WAIT.getValue());
    ctx.addToLog(type, "HOME: " + HOME.getValue());
    ctx.addToLog(type, "CMDs: " + CMDS.getValue());
    Commander commander = new Commander(log -> {
        ctx.addToLogPlain(type, log);
    });
    List<String> commands = Arrays.asList(StringUtils.split(CMDS.getValue(), ","));
    // @formatter:off
    commander.execute(Boolean.valueOf(WAIT.getValue()), false, HOME.getValue(), true, commands);
    if (commander == null || commander.isError()) {
        ctx.addToLog(type, "error at commander: " + CMDS.getKey());
        return EChainResponse.Failed;
    }
    return EChainResponse.Continue;
}
Also used : KeyValue(com.fo0.robot.model.KeyValue) Commander(com.fo0.robot.commander.Commander)

Aggregations

Commander (com.fo0.robot.commander.Commander)2 KeyValue (com.fo0.robot.model.KeyValue)2