Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W7][M11-1]Hu Yidi #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ Views all details of the 1st person in the results of the `find` command.
Clears all entries from the address book. +
Format: `clear`

== Giving the number of all commands entered : `all`

Gives the number of all commands entered to the address book. +
Format: `all`

== Exiting the program : `exit`

Exits the program. +
Expand Down
21 changes: 21 additions & 0 deletions src/seedu/addressbook/commands/AllCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.addressbook.commands;

import java.util.List;
import seedu.addressbook.parser.Parser;

public class AllCommand extends Command {

public static final String COMMAND_WORD = "all";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Total number of commands entered.\n"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_SUCCESS = "Number of all commands entered:";

@Override
public CommandResult execute() {

int totalnumber = Parser.allcommands;
return new CommandResult(MESSAGE_SUCCESS+totalnumber);
}
}
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class HelpCommand extends Command {
+ "Example: " + COMMAND_WORD;

public static final String MESSAGE_ALL_USAGES = AddCommand.MESSAGE_USAGE
+ "\n" + AllCommand.MESSAGE_USAGE
+ "\n" + DeleteCommand.MESSAGE_USAGE
+ "\n" + ClearCommand.MESSAGE_USAGE
+ "\n" + FindCommand.MESSAGE_USAGE
Expand Down
13 changes: 13 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Parser {
+ " (?<isAddressPrivate>p?)a/(?<address>[^/]+)"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags

public static int allcommands;

/**
* Signals that the user input could not be parsed.
Expand Down Expand Up @@ -58,27 +59,39 @@ public Command parseCommand(String userInput) {
switch (commandWord) {

case AddCommand.COMMAND_WORD:
allcommands ++;
return prepareAdd(arguments);

case AllCommand.COMMAND_WORD:
allcommands ++;
return new AllCommand();

case DeleteCommand.COMMAND_WORD:
allcommands ++;
return prepareDelete(arguments);

case ClearCommand.COMMAND_WORD:
allcommands ++;
return new ClearCommand();

case FindCommand.COMMAND_WORD:
allcommands ++;
return prepareFind(arguments);

case ListCommand.COMMAND_WORD:
allcommands ++;
return new ListCommand();

case ViewCommand.COMMAND_WORD:
allcommands ++;
return prepareView(arguments);

case ViewAllCommand.COMMAND_WORD:
allcommands ++;
return prepareViewAll(arguments);

case ExitCommand.COMMAND_WORD:
allcommands ++;
return new ExitCommand();

case HelpCommand.COMMAND_WORD: // Fallthrough
Expand Down
6 changes: 6 additions & 0 deletions test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.parser.Parser;
import seedu.addressbook.storage.StorageFile;

import java.util.*;
Expand Down Expand Up @@ -109,6 +110,11 @@ public void execute_exit() throws Exception {
assertCommandBehavior("exit", ExitCommand.MESSAGE_EXIT_ACKNOWEDGEMENT);
}

@Test
public void execute_all() throws Exception {
assertCommandBehavior("all", AllCommand.MESSAGE_SUCCESS + Parser.allcommands);
}

@Test
public void execute_clear() throws Exception {
TestDataHelper helper = new TestDataHelper();
Expand Down
8 changes: 7 additions & 1 deletion test/java/seedu/addressbook/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public void unknownCommandWord_returnsHelp() {
/**
* Test 0-argument commands
*/


@Test
public void allCommand_parsedCorrectly() {
final String input = "all";
parseAndAssertCommandType(input, AllCommand.class);
}

@Test
public void helpCommand_parsedCorrectly() {
final String input = "help";
Expand Down