diff --git a/src/main/java/tutorlink/command/HelpCommand.java b/src/main/java/tutorlink/command/HelpCommand.java new file mode 100644 index 0000000000..66b809a744 --- /dev/null +++ b/src/main/java/tutorlink/command/HelpCommand.java @@ -0,0 +1,52 @@ +package tutorlink.command; + +import tutorlink.appstate.AppState; +import tutorlink.commons.Commons; +import tutorlink.exceptions.TutorLinkException; +import tutorlink.result.CommandResult; + +import java.util.HashMap; + +/** + * Represents a help command that displays usage information. + * This command shows a list of all available commands and their proper usage. + * This command is triggered using the "help" keyword. + */ +public class HelpCommand extends Command { + /** + * Command word that triggers this command + */ + public static final String COMMAND_WORD = "help"; + + /** + * Creates a new HelpCommand instance. + */ + public HelpCommand() { + } + + /** + * Executes the help command. + * Returns a command result containing the help message that lists + * all available commands and their usage. + * + * @param state The current state of the application + * @param arguments Command arguments (not used for help command) + * @return CommandResult containing the help message + * @throws TutorLinkException if there's an error executing the command + */ + @Override + public CommandResult execute(AppState state, HashMap arguments) throws TutorLinkException { + return new CommandResult(Commons.HELP_MESSAGE); + } + + /** + * Gets the argument prefixes that this command accepts. + * Help command doesn't accept any arguments. + * + * @return null since this command takes no arguments + */ + @Override + public String[] getArgumentPrefixes() { + return null; + } +} diff --git a/src/main/java/tutorlink/commons/Commons.java b/src/main/java/tutorlink/commons/Commons.java index 7fe562d0a1..e3f27e16df 100644 --- a/src/main/java/tutorlink/commons/Commons.java +++ b/src/main/java/tutorlink/commons/Commons.java @@ -49,4 +49,46 @@ public class Commons { //Exit public static final String EXIT = "Goodbye! See you soon!"; + + //Help + public static final String HELP_MESSAGE = """ + help: Displays list of commands + Example: help + + add_student: Adds a student to the class roster + Example: add_student i/A1234567X n/John Doe + + delete_student: Deletes a student from the class roster + Example: delete_student i/A1234567X + + list_student: Lists all students in the class + Example: list_student + + find_student: Finds a student in the class roster by name or matric number + Example: find_student i/A1234567X n/John Doe + + add_component: Adds a new grading component to the class + Example: add_component c/Quiz 1 w/30 m/50 + + delete_component: Deletes a grading component from the class + Example: delete_component c/Quiz 1 + + update_component: Updates a component with a new maxscore or weight + Example: update_component c/Quiz 1 w/40 m/60 + + list_component: Lists all grading components + Example: list_component + + add_grade: Adds a grade for a student for a specific component + Example: add_grade i/A1234567X c/Quiz 1 s/45 + + delete_grade: Deletes a student's grade for a specific component + Example: delete_grade i/A1234567X c/Quiz 1 + + list_grade: Lists all grades for a student + Example: list_grade i/A1234567X + + bye: Exits the program + Example: bye + """; } diff --git a/src/main/java/tutorlink/parser/Parser.java b/src/main/java/tutorlink/parser/Parser.java index 6d4fa2cccd..1eb1d3e665 100644 --- a/src/main/java/tutorlink/parser/Parser.java +++ b/src/main/java/tutorlink/parser/Parser.java @@ -14,7 +14,9 @@ import tutorlink.command.AddGradeCommand; import tutorlink.command.AddComponentCommand; import tutorlink.command.UpdateComponentCommand; +import tutorlink.command.HelpCommand; import tutorlink.exceptions.IllegalValueException; + import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -91,6 +93,9 @@ public Command getCommand(String line) { case ExitCommand.COMMAND_WORD: return new ExitCommand(); + case HelpCommand.COMMAND_WORD: + return new HelpCommand(); + default: return new InvalidCommand(); } @@ -102,7 +107,7 @@ public Command getCommand(String line) { * and are extracted into a map where each prefix is a key and the corresponding argument is the value. * * @param argumentPrefixes An array of valid argument prefixes (e.g., "n/", "i/"). - * @param line The user input containing command arguments. + * @param line The user input containing command arguments. * @return A {@code HashMap} where keys are prefixes (e.g., "n/", "i/") and values are the corresponding arguments. */ public HashMap getArguments(String[] argumentPrefixes, String line) throws IllegalValueException {