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

Help command #216

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
52 changes: 52 additions & 0 deletions src/main/java/tutorlink/command/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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;
}
}
43 changes: 43 additions & 0 deletions src/main/java/tutorlink/commons/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,47 @@ public class Commons {

//Exit
public static final String EXIT = "Goodbye! See you soon!";

//Help
public static final String HELP_MESSAGE = """
------------------- List of Commands --------------------

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the break line can be removed from the HELP_MESSAGE string?
Since it will be passed into ui.displayResult(), which will print break lines at the start and end again.

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
-------------------------------------------------------------""";
}
7 changes: 6 additions & 1 deletion src/main/java/tutorlink/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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<String, String> getArguments(String[] argumentPrefixes, String line) throws IllegalValueException {
Expand Down
Loading