Skip to content

Commit

Permalink
Improve command parsing and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsieu committed Oct 30, 2021
1 parent 7f739b6 commit 9cb586f
Show file tree
Hide file tree
Showing 60 changed files with 975 additions and 586 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
logger.info("----------------[USER COMMAND][" + commandText + "]");

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText);
Command command = addressBookParser.parse(commandText);
commandResult = command.execute(model);
model.getCommandHistory().pushCommand(command);
model.addCommandToHistory(commandText);
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CommandArgument.optionalMultiple;
import static seedu.address.logic.parser.CommandArgument.requiredSingle;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandArgument;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

Expand All @@ -18,20 +22,22 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Adds a person to the address book.",
requiredSingle(PREFIX_NAME, "name"),
requiredSingle(PREFIX_PHONE, "phone"),
requiredSingle(PREFIX_EMAIL, "email"),
requiredSingle(PREFIX_ADDRESS, "address"),
optionalMultiple(PREFIX_TAG, "tag")
).withExample(
CommandArgument.filled(PREFIX_NAME, "John Doe"),
CommandArgument.filled(PREFIX_PHONE, "98765432"),
CommandArgument.filled(PREFIX_EMAIL, "[email protected]"),
CommandArgument.filled(PREFIX_ADDRESS, "311, Clementi Ave 2, #02-25"),
CommandArgument.filled(PREFIX_TAG, "friends"),
CommandArgument.filled(PREFIX_TAG, "owesMoney")
);

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
Expand All @@ -15,8 +16,12 @@ public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Clears the address book. "
+ "Parameters: none";

public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Clears the address book."
);

private ReadOnlyAddressBook oldAddressBook;

@Override
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PREAMBLE;
import static seedu.address.logic.parser.CommandArgument.filled;
import static seedu.address.logic.parser.CommandArgument.requiredSingle;

import java.util.List;
import java.util.function.Predicate;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

Expand All @@ -18,10 +22,13 @@ public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Deletes the person identified by the index number used in the displayed person list.",
requiredSingle(PREFIX_PREAMBLE, "index")
).withExample(
filled(PREFIX_PREAMBLE, "1")
);

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";

Expand Down
35 changes: 22 additions & 13 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PREAMBLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CommandArgument.filled;
import static seedu.address.logic.parser.CommandArgument.optionalMultiple;
import static seedu.address.logic.parser.CommandArgument.optionalSingle;
import static seedu.address.logic.parser.CommandArgument.requiredSingle;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.Collections;
Expand All @@ -18,6 +23,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand All @@ -32,19 +38,22 @@
public class EditCommand extends Command {

public static final String COMMAND_WORD = "edit";

public static final String MESSAGE_USAGE =
COMMAND_WORD + ": Edits the details of the person identified "
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Edits the details of the person identified "
+ "by the index number used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE
+ "91234567 " + PREFIX_EMAIL + "[email protected]";
+ "Existing values will be overwritten by the input values.",
requiredSingle(PREFIX_PREAMBLE, "index"),
optionalSingle(PREFIX_NAME, "name"),
optionalSingle(PREFIX_PHONE, "phone"),
optionalSingle(PREFIX_EMAIL, "email"),
optionalSingle(PREFIX_ADDRESS, "address"),
optionalMultiple(PREFIX_TAG, "tag")
).withExample(
filled(PREFIX_PREAMBLE, "1"),
filled(PREFIX_PHONE, "91234567"),
filled(PREFIX_EMAIL, "[email protected]")
);

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand All @@ -56,7 +65,7 @@ public class EditCommand extends Command {
private Person editedPerson;

/**
* @param index index of the person in the filtered person list to edit
* @param index index of the person in the filtered person list to edit
* @param editPersonDescriptor details to edit the person with
*/
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/seedu/address/logic/commands/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;

/**
Expand All @@ -8,8 +9,11 @@
public class ExitCommand extends Command {

public static final String COMMAND_WORD = "exit";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Exists TaskMaster2103. "
+ "Parameters: none";

public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Exits TaskMaster2103."
);

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting TaskMaster2103 as requested ...";

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PREAMBLE;
import static seedu.address.logic.parser.CommandArgument.filled;
import static seedu.address.logic.parser.CommandArgument.requiredSingle;

import java.util.function.Predicate;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
Expand All @@ -15,13 +19,16 @@
* Keyword matching is case insensitive.
*/
public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Finds all persons whose names contain any of the specified keywords (case-insensitive)\n"
+ "and displays them as a list with index numbers.",
requiredSingle(PREFIX_PREAMBLE, "KEYWORD [MORE_KEYWORDS]...")
).withExample(
filled(PREFIX_PREAMBLE, "alice bob charlie")
);

private final NameContainsKeywordsPredicate predicate;

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;

/**
Expand All @@ -9,8 +10,10 @@ public class HelpCommand extends Command {

public static final String COMMAND_WORD = "help";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n"
+ "Example: " + COMMAND_WORD;
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Shows program usage instructions."
);

public static final String SHOWING_HELP_MESSAGE = "Opened help window.";

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.function.Predicate;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

Expand All @@ -15,10 +16,12 @@
public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Lists all persons in the address book."
);

public static final String MESSAGE_SUCCESS = "Listed all persons";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all persons in the address book. "
+ "Parameters: none";

private Predicate<? super Person> previousPredicate;

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/seedu/address/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import java.util.Optional;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.storage.CommandHistory;

public class RedoCommand extends Command {

public static final String COMMAND_WORD = "redo";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Redoes the last executed command. \n"
+ "Example: " + COMMAND_WORD;
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Redoes the last executed command."
);

public static final String MESSAGE_UNDO_SUCCESS = "Successfully redid: ";
public static final String MESSAGE_NOT_UNDONE = "Cannot redo any further.";

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import java.util.Optional;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.storage.CommandHistory;

public class UndoCommand extends Command {

public static final String COMMAND_WORD = "undo";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Undoes the last executed command. \n"
+ "Example: " + COMMAND_WORD;
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
COMMAND_WORD,
"Undoes the last executed command."
);
public static final String MESSAGE_UNDO_SUCCESS = "Successfully undid: ";
public static final String MESSAGE_NOT_UNDONE = "Cannot undo any further.";

Expand Down
29 changes: 19 additions & 10 deletions src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import static seedu.address.logic.parser.CliSyntax.PREFIX_CONTACT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PREAMBLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIMESTAMP;
import static seedu.address.logic.parser.CommandArgument.filled;
import static seedu.address.logic.parser.CommandArgument.optionalMultiple;
import static seedu.address.logic.parser.CommandArgument.optionalSingle;
import static seedu.address.logic.parser.CommandArgument.requiredSingle;

import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.TaskCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.CommandSpecification;
import seedu.address.model.Model;
import seedu.address.model.task.Task;

Expand All @@ -18,16 +24,19 @@ public class AddTaskCommand extends TaskCommand {
public static final String COMMAND_WORD = "add";
public static final String FULL_COMMAND_WORD = TaskCommand.COMMAND_WORD + " " + COMMAND_WORD;
public static final String MESSAGE_SUCCESS = "New task added: %1$s";
public static final String MESSAGE_USAGE = FULL_COMMAND_WORD
+ ": Adds a task with a given title to the task list.\n"
+ "Parameters: title (must be a non-empty string) "
+ "[" + PREFIX_DESCRIPTION + "DESCRIPTION] "
+ "[" + PREFIX_TIMESTAMP + "TIMESTAMP] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_CONTACT + "AB3 CONTACT]...\n"
+ "Example: " + FULL_COMMAND_WORD + " Do homework "
+ PREFIX_DESCRIPTION + "Physics assignment "
+ PREFIX_TIMESTAMP + "25/12/2020";
public static final CommandSpecification COMMAND_SPECS = new CommandSpecification(
FULL_COMMAND_WORD,
"Add a task with the given title field, and optionally a description, timestamp, tags and contacts.",
requiredSingle(PREFIX_PREAMBLE, "title"),
optionalSingle(PREFIX_DESCRIPTION, "description"),
optionalSingle(PREFIX_TIMESTAMP, "timestamp"),
optionalMultiple(PREFIX_TAG, "tag"),
optionalMultiple(PREFIX_CONTACT, "contact_name")
).withExample(
filled(PREFIX_PREAMBLE, "Do homework"),
filled(PREFIX_DESCRIPTION, "Physics assignment"),
filled(PREFIX_TIMESTAMP, "25-12-2020")
);

private final Task task;

Expand Down
Loading

0 comments on commit 9cb586f

Please sign in to comment.