Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#43 from jasmoon/master
Browse files Browse the repository at this point in the history
Enhance help/man command
  • Loading branch information
karenfrilya97 authored Mar 16, 2018
2 parents bcc4a6f + 6b15ae2 commit b2dcdeb
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/AboutUs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Responsibilities: Logic

'''

=== Jasmond Toh
=== Jasmund Toh

{empty}[http://github.com/jasmoon[github]]

Expand Down
13 changes: 11 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ e.g. typing *`help`* and pressing kbd:[Enter] will open the help window.
* Parameters can be in any order e.g. if the command specifies `n/NAME p/PHONE_NUMBER`, `p/PHONE_NUMBER n/NAME` is also acceptable.
====

=== Viewing help : `help`

Format: `help`
=== Viewing help : `help` or `man`

Shows the help menu or help for the `COMMAND_WORD` requested.

Format: `help`, `help COMMAND_WORD`, `man` or `man COMMAND_WORD`

Examples:

* `help`

* `man add`

=== Adding a person: `add`

Expand Down
49 changes: 44 additions & 5 deletions src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,59 @@
import seedu.address.commons.events.ui.ShowHelpRequestEvent;

/**
* Format full help instructions for every command for display.
* Format full help instructions for every command for display or command requested
*/
public class HelpCommand extends Command {

public static final String COMMAND_ALIAS = "man";
public static final String COMMAND_WORD = "help";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = COMMAND_WORD + "/" + COMMAND_ALIAS + ": "
+ "Shows program usage instructions.\n" + "Example: " + COMMAND_WORD;

public static final String SHOWING_HELP_MESSAGE = "Opened help window.";
private String commandRequest = null;


//@@author jasmoon
public HelpCommand() {
}

public HelpCommand(String args) {
commandRequest = args.trim();
}

@Override
public CommandResult execute() {
EventsCenter.getInstance().post(new ShowHelpRequestEvent());
return new CommandResult(SHOWING_HELP_MESSAGE);
if (commandRequest == null) {
EventsCenter.getInstance().post(new ShowHelpRequestEvent());
return new CommandResult(SHOWING_HELP_MESSAGE);

} else {
switch(commandRequest) {

case AddCommand.COMMAND_WORD:
return new CommandResult(AddCommand.MESSAGE_USAGE);

case EditCommand.COMMAND_WORD:
return new CommandResult(EditCommand.MESSAGE_USAGE);

case SelectCommand.COMMAND_WORD:
return new CommandResult(SelectCommand.MESSAGE_USAGE);

case DeleteCommand.COMMAND_WORD:
return new CommandResult(DeleteCommand.MESSAGE_USAGE);

case FindCommand.COMMAND_WORD:
return new CommandResult(FindCommand.MESSAGE_USAGE);

default:
return new CommandResult(MESSAGE_USAGE);
}
}
}

public String getCommandRequest() {
return commandRequest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public Command parseCommand(String userInput) throws ParseException {
return new ExitCommand();

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

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

case UndoCommand.COMMAND_WORD:
return new UndoCommand();
Expand Down
60 changes: 60 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,60 @@
package seedu.address.logic.parser;

import java.util.ArrayList;

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



//@@author jasmoon

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

public final ArrayList<String> availableCommands;

/**
* HelpCommandParser constructor - creates an ArrayList which contains all commands open to the help function.
*/
public HelpCommandParser() {
availableCommands = new ArrayList<String>();
availableCommands.add("add");
availableCommands.add("delete");
availableCommands.add("edit");
availableCommands.add("find");
availableCommands.add("select");
}

/**
* Parses the given {@code String} of arguments in the context of the HelpCommand
* and returns an HelpCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/

public HelpCommand parse(String args) throws ParseException {

String commandRequest = args.trim();
if (commandRequest.length() == 0) {
return new HelpCommand();
} else {
if (availableCommands.contains(commandRequest)) {
return new HelpCommand(args);
} else {
throw new ParseException(formInvalidMessage(commandRequest));
}
}
}

/**
*
* @param commandRequest
* @return String message for invalid command request.
*/
private String formInvalidMessage(String commandRequest) {
return "Help for '" + commandRequest + "' is unknown or not available.";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,19 @@ public void parseCommand_find() throws Exception {

@Test
public void parseCommand_help() throws Exception {

//@@author jasmoon
assertTrue(parser.parseCommand(HelpCommand.COMMAND_WORD) instanceof HelpCommand);
assertTrue(parser.parseCommand(HelpCommand.COMMAND_WORD + " 3") instanceof HelpCommand);
assertTrue(parser.parseCommand(HelpCommand.COMMAND_ALIAS + " find") instanceof HelpCommand);
try {
parser.parseCommand(HelpCommand.COMMAND_WORD + " 3");
fail("The expected ParseException was not thrown");
} catch (ParseException pe) {
assertEquals("Help for '3' is unknown or not available.", pe.getMessage());
}
//need help with this test
//HelpCommand command = (HelpCommand) parser.parseCommand(HelpCommand.COMMAND_WORD + " find");
//assertEquals(new HelpCommand("find").execute(), command.execute());
}

@Test
Expand Down

0 comments on commit b2dcdeb

Please sign in to comment.