diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 7e4858342..779409d92 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -133,6 +133,24 @@ Views all details of the 2nd person in the address book. `viewall 1` + Views all details of the 1st person in the results of the `find` command. +== View the last command you typed in previously : `last` + +Displays the last command you typed in(not including 'last') previously + +Format: `last` + +**** +Shows the latest command typed in. +**** + +Examples: + +* `add something` + +This is the previous command for demo. + +* `last` + +`add something` + +Displays the last command `add something` + == Clearing all entries : `clear` Clears all entries from the address book. + diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index ef2ed7d0e..dc6e1ee6f 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -18,6 +18,7 @@ public class HelpCommand extends Command { + "\n" + ListCommand.MESSAGE_USAGE + "\n" + ViewCommand.MESSAGE_USAGE + "\n" + ViewAllCommand.MESSAGE_USAGE + + "\n" + LastCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE + "\n" + ExitCommand.MESSAGE_USAGE; diff --git a/src/seedu/addressbook/commands/LastCommand.java b/src/seedu/addressbook/commands/LastCommand.java new file mode 100644 index 000000000..cff60c314 --- /dev/null +++ b/src/seedu/addressbook/commands/LastCommand.java @@ -0,0 +1,24 @@ +package seedu.addressbook.commands; + +/** + * Show last command. + * Set the current command inside the input bar to last command. + */ +public class LastCommand extends Command{ + + public static final String COMMAND_WORD = "last"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + + "Last command typed: \n\t"; + + public String lastCommand; + + public LastCommand(String last) { + this.lastCommand = last; + } + + @Override + public CommandResult execute() { + return new CommandResult(MESSAGE_USAGE + lastCommand); + } +} diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 17afd61a0..c5c11a3d7 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -19,6 +19,8 @@ public class Logic { private StorageFile storage; private AddressBook addressBook; + private String lastCommand = ""; + /** The list of person shown to the user most recently. */ private List lastShownList = Collections.emptyList(); @@ -66,15 +68,30 @@ protected void setLastShownList(List newList) { /** * Parses the user command, executes it, and returns the result. + * Record this user command. * @throws Exception if there was any problem during command execution. */ public CommandResult execute(String userCommandText) throws Exception { + userCommandText = checkLastCommand(userCommandText); Command command = new Parser().parseCommand(userCommandText); CommandResult result = execute(command); recordResult(result); return result; } + /** + * Check if the command is "last". + * If yes then append the lastCommand for later execution. + */ + private String checkLastCommand(String userCommandText) throws Exception { + if( userCommandText.substring(0, Math.min(userCommandText.length(), 4)).equals("last")) { + userCommandText = userCommandText.concat(" ").concat(lastCommand); + } else { + lastCommand = userCommandText; + } + return userCommandText; + } + /** * Executes the command, updates storage, and returns the result. * diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 58f4f7e6c..f7d1bdcd9 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -78,9 +78,12 @@ public Command parseCommand(String userInput) { case ViewAllCommand.COMMAND_WORD: return prepareViewAll(arguments); + case LastCommand.COMMAND_WORD: + return new LastCommand(arguments); + case ExitCommand.COMMAND_WORD: return new ExitCommand(); - + case HelpCommand.COMMAND_WORD: // Fallthrough default: return new HelpCommand(); diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 396fb4bc9..372c478d9 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -456,6 +456,21 @@ public void execute_find_matchesIfAnyKeywordPresent() throws Exception { expectedList); } + /** + * The testing function for the newly implement command -LastCommand + * cannot be implemented because the result of the execution depends + * on the previous executed command. + + @Test + public void execute_LastCommand() throws Exception { + + } + + * It should return the last command user typed in previously. + */ + + + /** * A utility class to generate test data. */ diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 5b5f5b013..52c1611ad 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -58,6 +58,12 @@ public void listCommand_parsedCorrectly() { parseAndAssertCommandType(input, ListCommand.class); } + @Test + public void LastCommand_parsedCorrectly() { + final String input = "last"; + parseAndAssertCommandType(input, LastCommand.class); + } + @Test public void exitCommand_parsedCorrectly() { final String input = "exit";