public Object execute(CommandContext commandContext, Object... objects) throws Exception {
env.getVariables().set(CURRENT_NODE, gn);
if (objects.length > 0) {
try {
String cmdId = String.valueOf(objects[0]);
Node n = gn.find(cmdId);
if (n == null) {
n = layout.find(cmdId);
}
CommandContext ctx = commandContext;
Command cmd;
if (n instanceof CommandNode) {
cmd = lookup(((CommandNode) n).getId());
} else if (n instanceof GroupNode) {
cmd = new GroupCommand(cmdId, (GroupNode) n);
} else if (n instanceof AliasNode) {
cmd = lookup(((AliasNode) n).getCommand().substring(ALIAS_PREFIX.length()));
} else {
throw new IllegalStateException("Unrecognized node type: " + n.getClass().getName());
}
return cmd.execute(ctx, Arguments.shift(objects));
} finally {
env.getVariables().unset(CURRENT_NODE);
}