Skip to content

Commit

Permalink
Tweak error messages and help messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zekone committed Nov 9, 2023
1 parent 79be563 commit e75d107
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_MISSING_SECONDARY_COMMAND =
"Please be more specific. Type 'help %1$s' for more details.";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_START_TIME_AFTER_END_TIME = "Start time %s is after the end time %s!\n";
public static final String MESSAGE_INVALID_INTEGER_ARGUMENT =
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/seedu/address/logic/commands/ListEventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ public class ListEventCommand extends ListCommand {
public static final String MESSAGE_DESCENDING = "(in descending order):\n";

public static final String MESSAGE_USAGE = COMMAND_WORD + " " + SECONDARY_COMMAND_WORD
+ " [-descending] [-st filter_start_time] [-et filter_end_time]"
+ " (-st and -et must either both present or both not present)";
+ ": Shows a list of all events or events within a specified time interval.\n"
+ "Usage: " + COMMAND_WORD + " " + SECONDARY_COMMAND_WORD
+ " [-descending] [-st filter_start_time] [-et filter_end_time]"
+ " (-st and -et must either both present or both not present)";

private LocalDateTime filterStartTime;
private LocalDateTime filterEndTime;
private boolean sortAscending;

/**
* Constructor for {@code ListEventCommand} class
*
* @param filterStartTime The start time for filter
* @param filterEndTime The end time for filter
* @param sortAscending Set to {@code true} to sort the events by start time in ascending order,
* {@code false} in descending order.
* @param filterEndTime The end time for filter
* @param sortAscending Set to {@code true} to sort the events by start time
* in ascending order,
* {@code false} in descending order.
*/
public ListEventCommand(EventTime filterStartTime, EventTime filterEndTime, boolean sortAscending) {
this.filterStartTime = filterStartTime != null ? filterStartTime.getTime() : null;
Expand All @@ -54,8 +58,7 @@ public CommandResult execute(Model model) throws CommandException {
} else {
model.updateFilteredEventList(
evt -> DateTimeUtil.withinTimeInterval(this.filterStartTime, this.filterEndTime,
evt.getStartTime())
);
evt.getStartTime()));
result = MESSAGE_FILTERED;
}
result += this.sortAscending ? MESSAGE_ASCENDING : MESSAGE_DESCENDING;
Expand All @@ -65,8 +68,9 @@ public CommandResult execute(Model model) throws CommandException {
return (startTime1.isBefore(startTime2)
? 1
: startTime1.equals(startTime2)
? 0
: -1) * (sortAscending ? -1 : 1);
? 0
: -1)

Check warning on line 72 in src/main/java/seedu/address/logic/commands/ListEventCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ListEventCommand.java#L71-L72

Added lines #L71 - L72 were not covered by tests
* (sortAscending ? -1 : 1);
});
result += StringUtil.eventListToString(eventList);
return new CommandResult(result, false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ public class ListPersonCommand extends ListCommand {

public static final String MESSAGE_USAGE = COMMAND_WORD + " "
+ SECONDARY_COMMAND_WORD
+ ": Lists contacts in the address book."
+ "Parameters: "
+ PREFIX_TAG + " TAGNAME...\n"
+ "Tag argument may be empty."
+ ": Lists contacts in the address book.\n"
+ "Usage: "
+ COMMAND_WORD + " " + SECONDARY_COMMAND_WORD
+ " [" + PREFIX_TAG + " TAGNAME...]\n"
+ "Example: \n"
+ "- " + COMMAND_WORD + " " + SECONDARY_COMMAND_WORD + "\n"
+ "- " + COMMAND_WORD + " " + SECONDARY_COMMAND_WORD + " " + PREFIX_TAG + " recruiter";

private final Set<Tag> tags;

/**
* Creates a ListPersonCommand to list contacts based on tags (may be empty) {@code Person}
* Creates a ListPersonCommand to list contacts based on tags (may be empty)
* {@code Person}
*/
public ListPersonCommand(Set<Tag> tags) {
requireNonNull(tags);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_MISSING_SECONDARY_COMMAND;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;

import seedu.address.logic.commands.AddCommand;
Expand All @@ -17,6 +18,11 @@ public class AddCommandParser implements Parser<AddCommand> {
@Override
public AddCommand parse(String userInput) throws ParseException {
String secondaryCommandWord = SecondaryCommandSelector.getSecondaryCommandWord(userInput);

if (secondaryCommandWord == null) {
throw new ParseException(String.format(MESSAGE_MISSING_SECONDARY_COMMAND, AddCommand.COMMAND_WORD));

Check warning on line 23 in src/main/java/seedu/address/logic/parser/AddCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddCommandParser.java#L23

Added line #L23 was not covered by tests
}

String args = SecondaryCommandSelector.getArguments(secondaryCommandWord, userInput);
switch (secondaryCommandWord) {
case AddPersonCommand.SECONDARY_COMMAND_WORD:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_MISSING_SECONDARY_COMMAND;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;

import seedu.address.logic.commands.DeleteCommand;
Expand All @@ -16,6 +17,11 @@ public class DeleteCommandParser implements Parser<DeleteCommand> {
@Override
public DeleteCommand parse(String userInput) throws ParseException {
String secondaryCommandWord = SecondaryCommandSelector.getSecondaryCommandWord(userInput);

if (secondaryCommandWord == null) {
throw new ParseException(String.format(MESSAGE_MISSING_SECONDARY_COMMAND, DeleteCommand.COMMAND_WORD));

Check warning on line 22 in src/main/java/seedu/address/logic/parser/DeleteCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/DeleteCommandParser.java#L22

Added line #L22 was not covered by tests
}

String args = SecondaryCommandSelector.getArguments(secondaryCommandWord, userInput);
switch (secondaryCommandWord) {
case DeletePersonCommand.SECONDARY_COMMAND_WORD:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_MISSING_SECONDARY_COMMAND;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;

import seedu.address.logic.commands.ListCommand;
Expand All @@ -14,6 +15,11 @@ public class ListCommandParser implements Parser<ListCommand> {
@Override
public ListCommand parse(String userInput) throws ParseException {
String secondaryCommandWord = SecondaryCommandSelector.getSecondaryCommandWord(userInput);

if (secondaryCommandWord == null) {
throw new ParseException(String.format(MESSAGE_MISSING_SECONDARY_COMMAND, ListCommand.COMMAND_WORD));

Check warning on line 20 in src/main/java/seedu/address/logic/parser/ListCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/ListCommandParser.java#L20

Added line #L20 was not covered by tests
}

String args = SecondaryCommandSelector.getArguments(secondaryCommandWord, userInput);
switch (secondaryCommandWord) {
case ListPersonCommand.SECONDARY_COMMAND_WORD:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package seedu.address.logic.parser;

import seedu.address.logic.parser.exceptions.ParseException;

/**
* Helper methods for parsing secondary commands
*/
public abstract class SecondaryCommandSelector {

/**
* Get the secondary command word. For example, the command word {@code event} in the comman {@code add event ...}
* Get the secondary command word. For example, the command word {@code event}
* in the comman {@code add event ...}
*
* @param str The command arguments after the primary command word
* @return The secondary command word
*/
public static String getSecondaryCommandWord(String str) throws ParseException {
public static String getSecondaryCommandWord(String str) {
try {
return str.split(" ")[1];
} catch (Exception e) {
throw new ParseException("Can not get secondary command");
return null;

Check warning on line 19 in src/main/java/seedu/address/logic/parser/SecondaryCommandSelector.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/SecondaryCommandSelector.java#L19

Added line #L19 was not covered by tests
}

}

/**
* Get the arguments after secondary command word
* param str The command arguments after the primary command word
*
* @return The arguments after secondary command word
*/
public static String getArguments(String secondaryCommandWord, String str) {
Expand Down

0 comments on commit e75d107

Please sign in to comment.