From 8d5828d65e6af14b2192c5de7172d4774b1915c4 Mon Sep 17 00:00:00 2001 From: Lingxi Xing Date: Sun, 10 Sep 2023 20:18:44 +0800 Subject: [PATCH] feat: Friendlier syntax for commands User has to type out full command words. I'm a lazy Neovim user and hate typing verbose commands. Add some shorter aliases for all commands. New mappings (while retaining old ones): * "exit": EXIT * "q": EXIT * "ls": LIST_TASKS * "td": ADD_TODO * "dl": ADD_DEADLINE * "ev": ADD_EVENT * "m": MARK_TASK * "u": UNMARK_TASK * "rm": DELETE_TASK * "f": FIND_TASK --- src/main/java/duke/commands/CommandType.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/duke/commands/CommandType.java b/src/main/java/duke/commands/CommandType.java index a69a6036ea..937e6804b8 100644 --- a/src/main/java/duke/commands/CommandType.java +++ b/src/main/java/duke/commands/CommandType.java @@ -1,5 +1,8 @@ package duke.commands; +import java.util.HashMap; +import java.util.Map; + import duke.exceptions.DukeInvalidCommandException; /** @@ -17,6 +20,19 @@ public enum CommandType { DELETE_TASK("delete"), FIND_TASK("find"); + /** Shorter aliases for ease of use */ + private static final Map commandMap = new HashMap<>(Map.of( + "exit", EXIT, + "q", EXIT, + "ls", LIST_TASKS, + "td", ADD_TODO, + "dl", ADD_DEADLINE, + "ev", ADD_EVENT, + "m", MARK_TASK, + "u", UNMARK_TASK, + "rm", DELETE_TASK, + "f", FIND_TASK)); + /** The string representation of the command. */ private final String value; @@ -37,6 +53,10 @@ private CommandType(String value) { * @throws DukeInvalidCommandException If the command does not exist. */ public static CommandType fromString(String value) throws DukeInvalidCommandException { + if (commandMap.containsKey(value)) { + return commandMap.get(value); + } + for (CommandType command : CommandType.values()) { if (command.value.equalsIgnoreCase(value)) { return command;