diff --git a/src/main/java/seedu/address/logic/commands/SortCommand.java b/src/main/java/seedu/address/logic/commands/SortCommand.java index 9b8cfb3cece..814568cf03d 100644 --- a/src/main/java/seedu/address/logic/commands/SortCommand.java +++ b/src/main/java/seedu/address/logic/commands/SortCommand.java @@ -25,6 +25,8 @@ public class SortCommand extends Command { public static final String MESSAGE_SUCCESS = "List sorted based on %1$s in %2$s order"; public static final String RESET_MESSAGE_SUCCESS = "List sorting set to default order."; + public static final String MESSAGE_INVALID_ORDER = "Order should only be asc or desc."; + public static final String MESSAGE_INVALID_FIELD = "Field should only be github, name, telegram or reset."; private final PersonComparator comparator; public SortCommand(PersonComparator comparator) { diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 914f02bcefb..071d1b51d40 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -25,6 +25,8 @@ public DeleteCommand parse(String args) throws ParseException { if (!arePrefixesPresent(argMultimap, PREFIX_NAME) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE)); } + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME); + Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); return new DeleteCommand(name); diff --git a/src/main/java/seedu/address/logic/parser/SortCommandParser.java b/src/main/java/seedu/address/logic/parser/SortCommandParser.java index 3652f4e1853..63a73fe44d6 100644 --- a/src/main/java/seedu/address/logic/parser/SortCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/SortCommandParser.java @@ -71,7 +71,7 @@ private static SortOrder parseSortOrder(String userInput) throws ParseException } else if (userInput.trim().equalsIgnoreCase("desc")) { return SortOrder.DESC; } else { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE)); + throw new ParseException(SortCommand.MESSAGE_INVALID_ORDER); } } @@ -87,7 +87,7 @@ private static SortField parseSortField(String userInput) throws ParseException case "telegram" -> SortField.TELEGRAM; case "reset" -> SortField.NONE; default -> - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE)); + throw new ParseException(SortCommand.MESSAGE_INVALID_FIELD); }; } diff --git a/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java b/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java index d37a15f3e0a..0dd3bfbc98f 100644 --- a/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java @@ -37,11 +37,11 @@ public void parse_emptyArg_throwsParseException() { public void parse_invalidValues_throwsParseException() { // invalid field assertParseFailure(parser, PREAMBLE_NON_EMPTY + ORDER_DESC_DESC, - String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE)); + SortCommand.MESSAGE_INVALID_FIELD); // invalid order assertParseFailure(parser, VALID_FIELD_NAME + INVALID_ORDER_DESC, - String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE)); + SortCommand.MESSAGE_INVALID_ORDER); } @Test