Use find_and_execute_handler to dispatch commands in cmd_move

This commit is contained in:
David Eklov 2016-07-18 00:42:40 -05:00
parent 50fc18704e
commit 27845ddf18

View file

@ -1207,37 +1207,28 @@ static struct cmd_results *cmd_move_position(int argc, char **argv) {
} }
static struct cmd_results *cmd_move(int argc, char **argv) { static struct cmd_results *cmd_move(int argc, char **argv) {
struct cmd_results *result;
if (config->reading) { if (config->reading) {
return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file.");
} }
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
if (strcasecmp(argv[0], "left") == 0) { static const struct cmd_handler handlers[] = {
result = cmd_move_left(argc - 1, argv + 1); {"container", cmd_move_container},
} else if (strcasecmp(argv[0], "right") == 0) { {"down", cmd_move_down},
result = cmd_move_right(argc - 1, argv + 1); {"left", cmd_move_left},
} else if (strcasecmp(argv[0], "up") == 0) { {"position", cmd_move_position},
result = cmd_move_up(argc - 1, argv + 1); {"right", cmd_move_right},
} else if (strcasecmp(argv[0], "down") == 0) { {"scratchpad", cmd_move_scratchpad},
result = cmd_move_down(argc - 1, argv + 1); {"up", cmd_move_up},
} else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { {"window", cmd_move_container},
result = cmd_move_container(argc - 1, argv + 1); {"workspace", cmd_move_workspace},
} else if (strcasecmp(argv[0], "workspace") == 0) { };
result = cmd_move_workspace(argc - 1, argv + 1);
} else if (strcasecmp(argv[0], "scratchpad") == 0) {
result = cmd_move_scratchpad(argc - 1, argv + 1);
} else if (strcasecmp(argv[0], "position") == 0 && strcasecmp(argv[1], "mouse") == 0) {
result = cmd_move_position(argc - 1, argv + 1);
} else {
result = cmd_results_new(CMD_INVALID, "move", cmd_move_expected_syntax);
}
return result; return find_and_execute_handler(argc, argv, handlers, ARRAY_SIZE(handlers), cmd_move_expected_syntax);
} }
static struct cmd_results *cmd_new_float(int argc, char **argv) { static struct cmd_results *cmd_new_float(int argc, char **argv) {