Skip to content

Commit d116b74

Browse files
committed
Add help command with full command guide
1 parent 3d9dc6c commit d116b74

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package flora.command;
2+
3+
import flora.storage.Storage;
4+
import flora.task.TaskList;
5+
6+
/**
7+
* Command to display a guide of all available commands.
8+
*/
9+
public class HelpCommand extends Command {
10+
11+
private static final String HELP_MESSAGE = """
12+
Try one of these commands!
13+
14+
Adding tasks
15+
• todo <description>
16+
• deadline <description> /by <date>
17+
(shortcuts: today, tomorrow, next week...)
18+
• event <description> /from <start> /to <end>
19+
20+
Viewing tasks
21+
• list
22+
• find <keyword>
23+
24+
Managing tasks
25+
• mark <task number>
26+
• unmark <task number>
27+
• delete <task number>
28+
• edit <task number> [/desc ..] [/by ..] [/from ..] [/to ..]
29+
30+
Other
31+
• help — show this guide
32+
• bye — exit Flora
33+
34+
Date format: d/M/yyyy or d/M/yyyy H:mm
35+
e.g. 25/12/2025 or 25/12/2025 14:00""";
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
@Override
41+
public void execute(TaskList tasks, Storage storage) {
42+
// No side effects needed.
43+
}
44+
45+
/**
46+
* {@inheritDoc}
47+
*/
48+
@Override
49+
public String getMessage() {
50+
return HELP_MESSAGE;
51+
}
52+
}

src/main/java/flora/parser/Parser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import flora.command.EditCommand;
1717
import flora.command.ExitCommand;
1818
import flora.command.FindCommand;
19+
import flora.command.HelpCommand;
1920
import flora.command.ListCommand;
2021
import flora.command.MarkCommand;
2122
import flora.command.UnmarkCommand;
@@ -55,9 +56,10 @@ public static Command parse(String input) throws FloraException {
5556
case "mark" -> new MarkCommand(getTaskIndex(input, firstSpaceIndex));
5657
case "unmark" -> new UnmarkCommand(getTaskIndex(input, firstSpaceIndex));
5758
case "list" -> new ListCommand();
59+
case "help" -> new HelpCommand();
5860
case "bye" -> new ExitCommand();
5961
default -> throw new FloraException("Sorry, I don't recognize that command.\n"
60-
+ "Try one of: todo, deadline, event, list, find, edit, mark, unmark, delete, bye");
62+
+ "Type 'help' to see all available commands.");
6163
};
6264
}
6365

src/test/java/flora/FloraTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import flora.command.EditCommand;
2525
import flora.command.ExitCommand;
2626
import flora.command.FindCommand;
27+
import flora.command.HelpCommand;
2728
import flora.command.ListCommand;
2829
import flora.command.MarkCommand;
2930
import flora.command.UnmarkCommand;
@@ -1224,6 +1225,27 @@ public void nonExitCommand_isExit_returnsFalse() throws FloraException {
12241225
assertFalse(cmd.isExit());
12251226
}
12261227

1228+
// ==================== Command: HelpCommand ====================
1229+
1230+
@Test
1231+
public void parser_parseHelp_returnsHelpCommand() throws FloraException {
1232+
Command cmd = Parser.parse("help");
1233+
assertInstanceOf(HelpCommand.class, cmd);
1234+
}
1235+
1236+
@Test
1237+
public void helpCommand_getMessage_returnsNonBlank() {
1238+
HelpCommand cmd = new HelpCommand();
1239+
cmd.execute(new TaskList(), null);
1240+
assertFalse(cmd.getMessage().isBlank());
1241+
}
1242+
1243+
@Test
1244+
public void helpCommand_isExit_returnsFalse() {
1245+
HelpCommand cmd = new HelpCommand();
1246+
assertFalse(cmd.isExit());
1247+
}
1248+
12271249
// ==================== FloraException ====================
12281250

12291251
@Test

0 commit comments

Comments
 (0)