Skip to content

Commit

Permalink
Merge pull request #68 from Pengyuz/master
Browse files Browse the repository at this point in the history
Helpcommand
  • Loading branch information
dalessr authored Oct 25, 2017
2 parents 0f032f8 + 01d2418 commit d01973f
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -610,19 +610,19 @@ Moreover, if there is more than one person in the list with the name give, then

==== Design Considerations

**Aspect:** Implementation of `DeleteCommandParser`+
**Aspect:** Implementation of `DeleteCommandParser` +
**Alternative 1 (current choice):** Add a prefix after the command word to distinguish between delete by name or indexes. +
**Pros:** It is more convenient to identify the type of input to deal with.+
**Pros:** It is more convenient to identify the type of input to deal with. +
**Cons:** It is less convenient for users to type in the prefix. +
**Alternative 2:** Use the type of first input word after command word to differentiate. +
**Pros:** It is more convenient for the users to type.+
**Pros:** It is more convenient for the users to type. +
**Cons:** It is harder for the developer to find the type if the users give a name with all numbers to a contact.

---

**Aspect:** How to deal with multiple persons with same name condition +
**Alternative 1 (current choice):** Do not delete the persons and show all the persons with the same target name on the list. Remind the user to decide which one to delete. +
**Pros:** It considers more about the users. Try to ensure the target is the person who the users want to delete.+
**Pros:** It considers more about the users. Try to ensure the target is the person who the users want to delete. +
**Cons:** It cost users more time to delete a person if they don't know the index of the target. +
**Alternative 2:** Delete the first person with the name in the list and show it to user. +
**Pros:** It cost users less time to delete a person if they know the sequence of the persons with the same name. +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ClearCommand extends UndoableCommand {

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 + ": Clear all the person in the list.";


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ExitCommand extends Command {


public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Exit iConnect";

@Override
public CommandResult execute() {
Expand Down
47 changes: 45 additions & 2 deletions src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,53 @@ public class HelpCommand extends Command {
+ "Example: " + COMMAND_WORD;

public static final String SHOWING_HELP_MESSAGE = "Opened help window.";
private String commandword = "";
public HelpCommand() {}
public HelpCommand(String args) {
commandword = args;
}

@Override
public CommandResult execute() {
EventsCenter.getInstance().post(new ShowHelpRequestEvent());
return new CommandResult(SHOWING_HELP_MESSAGE);
if ("add".equals(commandword)) {
return new CommandResult(AddCommand.MESSAGE_USAGE);
} else if ("clear".equals(commandword)) {
return new CommandResult(ClearCommand.MESSAGE_USAGE);
} else if ("delete".equals(commandword)) {
return new CommandResult(DeleteCommand.MESSAGE_USAGE);
} else if ("edit".equals(commandword)) {
return new CommandResult(EditCommand.MESSAGE_USAGE);
} else if ("exit".equals(commandword)) {
return new CommandResult(ExitCommand.MESSAGE_USAGE);
} else if ("find".equals(commandword)) {
return new CommandResult(FindCommand.MESSAGE_USAGE);
} else if ("history".equals(commandword)) {
return new CommandResult(HistoryCommand.MESSAGE_USAGE);
} else if ("list".equals(commandword)) {
return new CommandResult(ListCommand.MESSAGE_USAGE);
} else if ("redo".equals(commandword)) {
return new CommandResult(RedoCommand.MESSAGE_USAGE);
} else if ("select".equals(commandword)) {
return new CommandResult(SelectCommand.MESSAGE_USAGE);
} else if ("sort".equals(commandword)) {
return new CommandResult(SortCommand.MESSAGE_USAGE);
} else if ("tagadd".equals(commandword)) {
return new CommandResult(TagAddCommand.MESSAGE_USAGE);
} else if ("tagremove".equals(commandword)) {
return new CommandResult(TagRemoveCommand.MESSAGE_USAGE);
} else if ("undo".equals(commandword)) {
return new CommandResult(UndoCommand.MESSAGE_USAGE);
} else {
EventsCenter.getInstance().post(new ShowHelpRequestEvent());
return new CommandResult(SHOWING_HELP_MESSAGE);
}

}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof HelpCommand // instanceof handles nulls
&& this.commandword.equals(((HelpCommand) other).commandword)); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class HistoryCommand extends Command {
public static final String COMMAND_WORD_2 = "record";
public static final String MESSAGE_SUCCESS = "Entered commands (from most recent to earliest):\n%1$s";
public static final String MESSAGE_NO_HISTORY = "You have not yet entered any commands.";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all the commands entered by "
+ "user from the start of app launch.";

@Override
public CommandResult execute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ListCommand extends Command {
public static final String COMMAND_WORD_3 = "all";

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


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class RedoCommand extends Command {
public static final String COMMAND_WORD = "redo";
public static final String MESSAGE_SUCCESS = "Redo success!";
public static final String MESSAGE_FAILURE = "No more commands to redo!";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Redo the previously undone command.";

@Override
public CommandResult execute() throws CommandException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class UndoCommand extends Command {
public static final String COMMAND_WORD = "undo";
public static final String MESSAGE_SUCCESS = "Undo success!";
public static final String MESSAGE_FAILURE = "No more commands to undo!";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Undo the previous undoable command.";

@Override
public CommandResult execute() throws CommandException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Command parseCommand(String userInput) throws ParseException {

case HelpCommand.COMMAND_WORD:
case HelpCommand.COMMAND_WORD_2:
return new HelpCommand();
return new HelpCommandParser().parse(arguments);

case UndoCommand.COMMAND_WORD:
return new UndoCommand();
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/seedu/address/logic/parser/HelpCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package seedu.address.logic.parser;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.SortCommand;
import seedu.address.logic.commands.TagAddCommand;
import seedu.address.logic.commands.TagRemoveCommand;
import seedu.address.logic.commands.UndoCommand;

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


/**
* Parses input arguments and creates a new SelectCommand object
*/
public class HelpCommandParser implements Parser<HelpCommand> {

/**
* Parses the given {@code String} of arguments in the context of the SelectCommand
* and returns an SelectCommand object for execution.
*/
public HelpCommand parse(String args) throws ParseException {
String input = args.toLowerCase().trim();

if (input.equals(AddCommand.COMMAND_WORD) || input.equals(AddCommand.COMMAND_WORD_2)
|| input.equals(AddCommand.COMMAND_WORD_3)) {
return new HelpCommand("add");
} else if (input.equals(ClearCommand.COMMAND_WORD)) {
return new HelpCommand("clear");
} else if (input.equals(DeleteCommand.COMMAND_WORD) || input.equals(DeleteCommand.COMMAND_WORD_2)
|| input.equals(DeleteCommand.COMMAND_WORD_3)) {
return new HelpCommand("delete");
} else if (input.equals(EditCommand.COMMAND_WORD) || input.equals(EditCommand.COMMAND_WORD_2)
|| input.equals(EditCommand.COMMAND_WORD_3)) {
return new HelpCommand("edit");
} else if (input.equals(ExitCommand.COMMAND_WORD)) {
return new HelpCommand("exit");
} else if (input.equals(FindCommand.COMMAND_WORD) || input.equals(FindCommand.COMMAND_WORD_2)
|| input.equals(FindCommand.COMMAND_WORD_3)) {
return new HelpCommand("find");
} else if (input.equals(HistoryCommand.COMMAND_WORD) || input.equals(HistoryCommand.COMMAND_WORD_2)) {
return new HelpCommand("history");
} else if (input.equals(ListCommand.COMMAND_WORD) || input.equals(ListCommand.COMMAND_WORD_2)
|| input.equals(ListCommand.COMMAND_WORD_3)) {
return new HelpCommand("list");
} else if (input.equals(RedoCommand.COMMAND_WORD)) {
return new HelpCommand("redo");
} else if (input.equals(SelectCommand.COMMAND_WORD) || input.equals(SelectCommand.COMMAND_WORD_2)) {
return new HelpCommand("select");
} else if (input.equals(SortCommand.COMMAND_WORD)) {
return new HelpCommand("sort");
} else if (input.equals(TagAddCommand.COMMAND_WORD)) {
return new HelpCommand("tagadd");
} else if (input.equals(TagRemoveCommand.COMMAND_WORD)) {
return new HelpCommand("tagremove");
} else if (input.equals(UndoCommand.COMMAND_WORD)) {
return new HelpCommand("undo");
} else {
return new HelpCommand();
}

}
}
45 changes: 45 additions & 0 deletions src/test/java/seedu/address/logic/commands/HelpCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,49 @@ public void execute_help_success() {
assertTrue(eventsCollectorRule.eventsCollector.getMostRecent() instanceof ShowHelpRequestEvent);
assertTrue(eventsCollectorRule.eventsCollector.getSize() == 1);
}

@Test
public void excutesuccess() {
CommandResult result = new HelpCommand("add").execute();
assertEquals(AddCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("clear").execute();
assertEquals(ClearCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("delete").execute();
assertEquals(DeleteCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("edit").execute();
assertEquals(EditCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("exit").execute();
assertEquals(ExitCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("find").execute();
assertEquals(FindCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("history").execute();
assertEquals(HistoryCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("list").execute();
assertEquals(ListCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("redo").execute();
assertEquals(RedoCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("select").execute();
assertEquals(SelectCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("sort").execute();
assertEquals(SortCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("tagadd").execute();
assertEquals(TagAddCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("tagremove").execute();
assertEquals(TagRemoveCommand.MESSAGE_USAGE, result.feedbackToUser);

result = new HelpCommand("undo").execute();
assertEquals(UndoCommand.MESSAGE_USAGE, result.feedbackToUser);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package seedu.address.logic.parser;

import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.Test;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.SortCommand;
import seedu.address.logic.commands.TagAddCommand;
import seedu.address.logic.commands.TagRemoveCommand;
import seedu.address.logic.commands.UndoCommand;














public class HelpCommandParserTest {
private HelpCommandParser parser = new HelpCommandParser();

@Test
public void parsesuccess() {
assertParseSuccess(parser, AddCommand.COMMAND_WORD, new HelpCommand("add"));

assertParseSuccess(parser, AddCommand.COMMAND_WORD_2, new HelpCommand("add"));

assertParseSuccess(parser, AddCommand.COMMAND_WORD_3, new HelpCommand("add"));

assertParseSuccess(parser, ClearCommand.COMMAND_WORD, new HelpCommand("clear"));

assertParseSuccess(parser, DeleteCommand.COMMAND_WORD, new HelpCommand("delete"));

assertParseSuccess(parser, DeleteCommand.COMMAND_WORD_2, new HelpCommand("delete"));

assertParseSuccess(parser, DeleteCommand.COMMAND_WORD_3, new HelpCommand("delete"));

assertParseSuccess(parser, EditCommand.COMMAND_WORD, new HelpCommand("edit"));

assertParseSuccess(parser, EditCommand.COMMAND_WORD_2, new HelpCommand("edit"));

assertParseSuccess(parser, EditCommand.COMMAND_WORD_3, new HelpCommand("edit"));

assertParseSuccess(parser, ExitCommand.COMMAND_WORD, new HelpCommand("exit"));

assertParseSuccess(parser, FindCommand.COMMAND_WORD, new HelpCommand("find"));

assertParseSuccess(parser, FindCommand.COMMAND_WORD_2, new HelpCommand("find"));

assertParseSuccess(parser, FindCommand.COMMAND_WORD_3, new HelpCommand("find"));

assertParseSuccess(parser, HistoryCommand.COMMAND_WORD, new HelpCommand("history"));

assertParseSuccess(parser, HistoryCommand.COMMAND_WORD_2, new HelpCommand("history"));

assertParseSuccess(parser, ListCommand.COMMAND_WORD, new HelpCommand("list"));

assertParseSuccess(parser, ListCommand.COMMAND_WORD_2, new HelpCommand("list"));

assertParseSuccess(parser, ListCommand.COMMAND_WORD_3, new HelpCommand("list"));

assertParseSuccess(parser, RedoCommand.COMMAND_WORD, new HelpCommand("redo"));

assertParseSuccess(parser, SelectCommand.COMMAND_WORD, new HelpCommand("select"));

assertParseSuccess(parser, SelectCommand.COMMAND_WORD_2, new HelpCommand("select"));

assertParseSuccess(parser, SortCommand.COMMAND_WORD, new HelpCommand("sort"));

assertParseSuccess(parser, TagAddCommand.COMMAND_WORD, new HelpCommand("tagadd"));

assertParseSuccess(parser, TagRemoveCommand.COMMAND_WORD, new HelpCommand("tagremove"));

assertParseSuccess(parser, UndoCommand.COMMAND_WORD, new HelpCommand("undo"));

}

}

0 comments on commit d01973f

Please sign in to comment.