Skip to content

Commit

Permalink
Restrict to non-empty preamble and other updates
Browse files Browse the repository at this point in the history
  • Loading branch information
liakify committed Nov 3, 2019
1 parent 43db25c commit 1a77bab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ This adds an expense of $15 by John Doe called `Cab` where only John himself is

Edits some details of the current contact or activity in view. Note that contact names must be unique, so if a specified name already exists in the address book, the edit will not be processed. +

Format: `edit [n/NAME] [p/PHONE] [tag/TAG] ...` for contacts OR `edit [t/ACTIVITY_TITLE]` for activities.
Format: `edit [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [tag/TAG] ...` for contacts OR `edit [t/ACTIVITY_TITLE]` for activities.

****
* At least one of the optional fields must be provided.
* Existing values will be updated to the input values.
* Irrelevant flags will be ignored. For example, `edit p/999 t/new title` when viewing an activity will only update the title to `new title`, and `p/999` will be ignored.
* Irrelevant parameters will be ignored. For example, `edit p/999 t/new title` when viewing an activity will only update the title to `new title`, and `p/999` will be ignored.
* Expenses cannot be edited.
****

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public class EditCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person or activity "
+ "currently in view.\n"
+ "Existing values will be overwritten by the input values, and irrelevant parameters will be ignored.\n"
+ "Parameters: [" + PREFIX_TITLE + "TITLE] "
+ "Parameters (editing contact): "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Examples: " + COMMAND_WORD + " "
+ "Parameters (editing activity) "
+ "[" + PREFIX_TITLE + "TITLE] \n"
+ "Examples: \n" + COMMAND_WORD + " "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "johndoe@example.com\n"
+ COMMAND_WORD + " " + PREFIX_TITLE + "Fun @ Chalet";
Expand Down Expand Up @@ -114,7 +116,7 @@ public CommandResult execute(Model model) throws CommandException {
* edited with {@code editPersonDescriptor}.
*/
private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) {
assert personToEdit != null;
requireNonNull(personToEdit);

Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Expand All @@ -132,7 +134,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
*/
private static Activity createEditedActivity(Activity activityToEdit,
EditActivityDescriptor editActivityDescriptor) {
assert activityToEdit != null;
requireNonNull(activityToEdit);

Title updatedTitle = editActivityDescriptor.getTitle().orElse(activityToEdit.getTitle());
return new Activity(activityToEdit, updatedTitle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
Expand Down Expand Up @@ -35,6 +36,10 @@ public EditCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_TAG, PREFIX_TITLE);

if (argMultimap.getPreamble().trim().length() > 0) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
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.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.DESC_ACTIVITY2;
Expand Down Expand Up @@ -51,6 +52,17 @@ public class EditCommandParserTest {

private EditCommandParser parser = new EditCommandParser();

@Test
public void parse_preambleTests() {
// Non-empty preamble -> failure
assertParseFailure(parser, " hi " + VALID_EMAIL_AMY,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));

// Whitespace preamble -> success
assertParseSuccess(parser, " " + TITLE_DESC_ACTIVITY2,
new EditCommand(new EditPersonDescriptor(), DESC_ACTIVITY2));
}

@Test
public void parse_invalidValue_failure() {
assertParseFailure(parser, INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name
Expand Down

0 comments on commit 1a77bab

Please sign in to comment.