diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..0109dc654 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -153,7 +153,10 @@ Views all details of the 1st person in the results of the `find` command. == Clearing all entries : `clear` +Warning message for clearing all data +Key in "YES" to continue Clears all entries from the address book. + +Any key to exit clear function Format: `clear` == Exiting the program : `exit` diff --git a/src/seedu/addressbook/commands/ClearCommand.java b/src/seedu/addressbook/commands/ClearCommand.java index 6f88f8e13..f53091342 100644 --- a/src/seedu/addressbook/commands/ClearCommand.java +++ b/src/seedu/addressbook/commands/ClearCommand.java @@ -1,4 +1,5 @@ package seedu.addressbook.commands; +import java.util.*; /** * Clears the address book. @@ -8,12 +9,21 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; public static final String MESSAGE_USAGE = "Clears address book permanently.\n" + "Example: " + COMMAND_WORD; - public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; + public static final String MESSAGE_FAILURE = "Exiting clear function"; + @Override public CommandResult execute() { - addressBook.clear(); - return new CommandResult(MESSAGE_SUCCESS); + System.out.println("Confirm to clear the entire address book? YES to continue"); + Scanner scanner = new Scanner(System.in); + String next = scanner.next(); + if (next.equals("YES")) { + addressBook.clear(); + return new CommandResult(MESSAGE_SUCCESS); + } + + return new CommandResult(MESSAGE_FAILURE); } } +