Skip to content

Commit 29fb4d9

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#108 from tohyuting/add-helpCommand
Add help command
2 parents 0d03303 + 9f8df2d commit 29fb4d9

File tree

9 files changed

+553
-14
lines changed

9 files changed

+553
-14
lines changed

src/main/java/seedu/clinic/logic/commands/FindCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class FindCommand extends Command {
2020
public static final String COMMAND_WORD = "find";
2121

2222
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all suppliers/warehouses that sell/hold products"
23-
+ "matching the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
23+
+ " matching the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
2424
+ "Parameters: TYPE KEYWORD [MORE_KEYWORDS...]\n"
25-
+ "Example: " + COMMAND_WORD + " supplier panadol"
25+
+ "Example: " + COMMAND_WORD + " supplier panadol\n"
2626
+ "Example: " + COMMAND_WORD + " warehouse face mask";
2727

2828
private final Optional<SupplierProductsContainKeywordsPredicate> supplierPredicate;

src/main/java/seedu/clinic/logic/commands/HelpCommand.java

Lines changed: 203 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,218 @@
33
import seedu.clinic.model.Model;
44

55
/**
6-
* Format full help instructions for every command for display.
6+
* Format full help instructions for respective help command to display.
77
*/
88
public class HelpCommand extends Command {
99

1010
public static final String COMMAND_WORD = "help";
1111

12-
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n"
13-
+ "Example: " + COMMAND_WORD;
12+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows all command with"
13+
+ " respective utility description\n"
14+
+ "Example: " + COMMAND_WORD + "\n\nSpecific commands with respective input samples "
15+
+ "can be shown as well \n" + "Example: help find";
16+
public static final String MESSAGE_TOO_MANY_ARGUMENTS = "You can only enter one command at a time\n\n"
17+
+ MESSAGE_USAGE;
18+
public static final String MESSAGE_WRONG_ARGUMENT = "You can only enter command from one of the "
19+
+ "following keywords: add, clear, delete, exit, find, view, update";
1420

1521
public static final String SHOWING_HELP_MESSAGE = "Opened help window.";
22+
public static final String[] ALLOWED_ARGUMENTS = new String[]{
23+
"add", "clear", "delete", "exit", "find", "list", "view", "update"};
24+
25+
public static final String HELP_MESSAGE_FOR_COMMAND_FORMAT = "How to interpret command format?\n"
26+
+ "Words in UPPER_CASE are the parameters to be supplied by the user."
27+
+ " Items in square brackets are optional. Items with ... after them can be used multiple times."
28+
+ " Parameters can be in any order.";
29+
30+
public static final String HELP_MESSAGE_FOR_USER_GUIDE = "Press F1 to copy the URL to view User Guide"
31+
+ " on our website for more details on each command sample";
32+
33+
private final String commandArgument;
34+
35+
/**
36+
* Constructs a new HelpCommand object.
37+
*
38+
* @param commandArgument takes in the command argument (if any) specified for help command.
39+
*/
40+
public HelpCommand(String commandArgument) {
41+
this.commandArgument = commandArgument;
42+
}
1643

1744
@Override
1845
public CommandResult execute(Model model) {
19-
return new CommandResult(SHOWING_HELP_MESSAGE, true, false);
46+
String helpMessage = "test";
47+
switch(commandArgument) {
48+
case "add":
49+
helpMessage = generateHelpAddMessage();
50+
break;
51+
case "clear":
52+
helpMessage = generateHelpClearMessage();
53+
break;
54+
case "delete":
55+
helpMessage = generateHelpDeleteMessage();
56+
break;
57+
case "exit":
58+
helpMessage = generateHelpExitMessage();
59+
break;
60+
case "find":
61+
helpMessage = generateHelpFindMessage();
62+
break;
63+
case "list":
64+
helpMessage = generateHelpListMessage();
65+
break;
66+
case "view":
67+
helpMessage = generateHelpViewMessage();
68+
break;
69+
case "update":
70+
helpMessage = generateHelpUpdateMessage();
71+
break;
72+
default:
73+
helpMessage = generateHelpGenericMessage();
74+
}
75+
76+
return new CommandResult(helpMessage, false, false);
77+
}
78+
79+
private String generateHelpGenericMessage() {
80+
String aboutHelpCommand = "You can view more of each command using \nhelp COMMAND.\n\n"
81+
+ "Sample Command:\nhelp find\n\nShows what find command does, command format and"
82+
+ " sample command(s) to follow.\n\n"
83+
+ "If you wish to learn more about sample commands found under"
84+
+ " each command, feel free to copy our website User Guide URL,"
85+
+ " which can be found by pressing F1.";
86+
87+
String aboutAddCommand = "add\nYou can add warehouse, supplier or product to a supplier using the add"
88+
+ " command";
89+
String aboutClearCommand = "clear\nYou can clear all entries (suppliers and warehouses)"
90+
+ " in CLI-nic using clear command.";
91+
String aboutDeleteCommand = "delete\nYou can delete warehouse or supplier that are no longer"
92+
+ " needed by using the delete command.";
93+
String aboutExitCommand = "exit\nYou can exit the application using the exit command.";
94+
String aboutFindCommand = "find\nYou can find suppliers or warehouses that sells the products using"
95+
+ " the find command.";
96+
String aboutListCommand = "list\nYou can list all suppliers and warehouses by using list command.";
97+
String aboutViewCommand = "view\nYou can view a specific warehouse or supplier using"
98+
+ " the view command.";
99+
String aboutUpdateCommand = "update\nYou can update stock of a product in the warehouse by"
100+
+ " using the update command";
101+
102+
String finalGenericHelpMessage = aboutHelpCommand + "\n\n" + aboutAddCommand + "\n\n"
103+
+ aboutClearCommand + "\n\n" + aboutDeleteCommand + "\n\n" + aboutExitCommand
104+
+ "\n\n" + aboutFindCommand + "\n\n" + aboutListCommand + "\n\n" + aboutViewCommand
105+
+ "\n\n" + aboutUpdateCommand;
106+
return finalGenericHelpMessage;
107+
}
108+
109+
private String generateHelpAddMessage() {
110+
String generalDescriptionOfAdd = "There are three types of add command to add warehouse,"
111+
+ " add supplier or add a product to a supplier.";
112+
113+
String addWarehouse = "Add Warehouse \nAdds warehouse to the CLI-nic application.";
114+
String addWarehouseCommandFormat = "Command format: \nadd w/WAREHOUSE_NAME p/CONTACT_NUMBER"
115+
+ " addr/ADDRESS" + " [r/WAREHOUSE_NOTE]";
116+
String addWarehouseSampleCommand = "Sample Command: \nadd w/warehouseA p/00000000"
117+
+ " addr/John street, block 123, #01-01 r/First warehouse";
118+
String finalAddWarehouse = addWarehouse + "\n\n" + addWarehouseCommandFormat + "\n\n"
119+
+ addWarehouseSampleCommand;
120+
121+
String addSupplier = "Add Supplier \nAdds a supplier to the CLI-nic application.";
122+
String addSupplierCommandFormat = "Command format: \nadd s/SUPPLIER_NAME pd/PRODUCT_NAME [t/TAG...]";
123+
String addSupplierSampleCommand = "Sample Command: \nadd s/Philips Pharmaceutical p/00000000"
124+
+ " e/[email protected] r/largest contractor";
125+
String finalAddSupplier = addSupplier + "\n\n" + addSupplierCommandFormat + "\n\n"
126+
+ addSupplierSampleCommand;
127+
128+
String addProductToSupplier = "Add Product to Supplier \nAdds product information to a supplier;"
129+
+ " associates a particular" + " product with the supplier in the CLI-nic application.";
130+
String addProductToSupplierCommandFormat = "Command format: \nadd s/SUPPLIER_NAME pd/PRODUCT_NAME"
131+
+ " [t/TAG...]";
132+
String addProductToSupplierSampleCommand = "Sample Command: \n"
133+
+ "add s/SupplierA pd/PANADOL SUSP t/FEVER";
134+
String finalAddProductToSupplier = addProductToSupplier + "\n\n" + addProductToSupplierCommandFormat
135+
+ "\n\n" + addProductToSupplierSampleCommand;
136+
137+
String addHelpMessage = HELP_MESSAGE_FOR_COMMAND_FORMAT + "\n\n" + generalDescriptionOfAdd + "\n\n"
138+
+ finalAddWarehouse + "\n\n" + finalAddSupplier + "\n\n" + finalAddProductToSupplier
139+
+ "\n\n" + HELP_MESSAGE_FOR_USER_GUIDE;
140+
141+
return addHelpMessage;
142+
}
143+
144+
private String generateHelpClearMessage() {
145+
return "Clear\n\nClear all entries (suppliers and warehouses) in CLI-nic.\n\nSample Command: \nclear";
146+
}
147+
148+
private String generateHelpDeleteMessage() {
149+
String deleteSupplierOrWarehouse = "Delete\nDelete entries of warehouses or suppliers that are"
150+
+ " not needed anymore.";
151+
String deleteSupplierOrWarehouseCommandFormat = "Command format: \ndelete TYPE INDEX";
152+
String deleteSupplierOrWarehouseSampleCommand = "Sample Command: \ndelete warehouse 1 \n"
153+
+ "delete supplier 12";
154+
155+
String deleteHelpMessage = HELP_MESSAGE_FOR_COMMAND_FORMAT + "\n\n" + deleteSupplierOrWarehouse
156+
+ "\n\n" + deleteSupplierOrWarehouseCommandFormat + "\n\n"
157+
+ deleteSupplierOrWarehouseSampleCommand + "\n\n" + HELP_MESSAGE_FOR_USER_GUIDE;
158+
return deleteHelpMessage;
159+
}
160+
161+
private String generateHelpExitMessage() {
162+
return "Exit\n\nExits the program.\n\nSample Command:\nexit";
163+
}
164+
165+
private String generateHelpFindMessage() {
166+
String findProductsInSupplierOrWarehouse = "Find\nFinds all suppliers or warehouses managed by the manager"
167+
+ " that sells the relevant medical products.";
168+
String findProductsInSupplierOrWarehouseCommandFormat = "Command format: \nfind TYPE KEYWORD...\n"
169+
+ "KEYWORD specified is case-insensitive.\n"
170+
+ "The TYPE specified should be one of these values: warehouse / supplier.";
171+
String findProductsInSupplierOrWarehouseSampleCommand = "Sample Command: \n"
172+
+ "find warehouse PANADOL SUSP \nfind supplier masks";
173+
String findHelpMessage = HELP_MESSAGE_FOR_COMMAND_FORMAT + "\n\n"
174+
+ findProductsInSupplierOrWarehouse + "\n\n"
175+
+ findProductsInSupplierOrWarehouseCommandFormat + "\n\n"
176+
+ findProductsInSupplierOrWarehouseSampleCommand + "\n\n" + HELP_MESSAGE_FOR_USER_GUIDE;
177+
return findHelpMessage;
178+
}
179+
180+
private String generateHelpListMessage() {
181+
return "List\n\nLists all suppliers and warehouses.\n\nSample Command:\nlist";
182+
}
183+
184+
private String generateHelpViewMessage() {
185+
String viewWarehouseOrSupplier = "View\nShows a particular supplier/warehouse with their relevant"
186+
+ " information e.g. products associated with the supplier/warehouse, address etc.";
187+
String viewWarehouseOrSupplierCommandFormat = "Command format: \nview TYPE NAME\n"
188+
+ "The TYPE specified should be one of these values: supplier or warehouse.\n"
189+
+ "The supplier/warehouse NAME specified is case-insensitive.";
190+
String viewWarehouseOrSupplierSampleCommand = "Sample Command: \nview supplier supplierA"
191+
+ "\nview warehouse warehouseB";
192+
String viewCommandHelpMessage = HELP_MESSAGE_FOR_COMMAND_FORMAT + "\n\n"
193+
+ viewWarehouseOrSupplier + "\n\n"
194+
+ viewWarehouseOrSupplierCommandFormat + "\n\n"
195+
+ viewWarehouseOrSupplierSampleCommand + "\n\n" + HELP_MESSAGE_FOR_USER_GUIDE;
196+
return viewCommandHelpMessage;
197+
}
198+
199+
private String generateHelpUpdateMessage() {
200+
String updateWarehouseProduct = "Update\nIf the product does not exist for that warehouse,"
201+
+ " it will associate the new product with the warehouse and the input quantity."
202+
+ " Otherwise, it will update the stock of the existing product with the new quantity.";
203+
String updateWarehouseProductCommandFormat = "Command format: \n"
204+
+ "update w/WAREHOUSE_NAME pd/PRODUCT_NAME q/QUANTITY";
205+
String updateWarehouseProductSampleCommand = "Sample Command: \n"
206+
+ "update w/WarehouseA pd/Panadol q/10";
207+
String updateCommandHelpMessage = HELP_MESSAGE_FOR_COMMAND_FORMAT + "\n\n"
208+
+ updateWarehouseProduct + "\n\n"
209+
+ updateWarehouseProductCommandFormat + "\n\n"
210+
+ updateWarehouseProductSampleCommand + "\n\n" + HELP_MESSAGE_FOR_USER_GUIDE;
211+
return updateCommandHelpMessage;
212+
}
213+
214+
@Override
215+
public boolean equals(Object other) {
216+
return other == this // short circuit if same object
217+
|| (other instanceof HelpCommand // instanceof handles nulls
218+
&& commandArgument.equals(((HelpCommand) other).commandArgument)); // state check
20219
}
21220
}

src/main/java/seedu/clinic/logic/parser/ClinicParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Command parseCommand(String userInput) throws ParseException {
6666
return new ExitCommand();
6767

6868
case HelpCommand.COMMAND_WORD:
69-
return new HelpCommand();
69+
return new HelpCommandParser().parse(arguments);
7070

7171
default:
7272
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package seedu.clinic.logic.parser;
2+
3+
import static seedu.clinic.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4+
import static seedu.clinic.logic.commands.HelpCommand.ALLOWED_ARGUMENTS;
5+
import static seedu.clinic.logic.commands.HelpCommand.MESSAGE_TOO_MANY_ARGUMENTS;
6+
import static seedu.clinic.logic.commands.HelpCommand.MESSAGE_WRONG_ARGUMENT;
7+
8+
import java.util.Arrays;
9+
10+
import seedu.clinic.logic.commands.HelpCommand;
11+
import seedu.clinic.logic.parser.exceptions.ParseException;
12+
13+
/**
14+
* Parses input arguments and creates a new HelpCommand object
15+
*/
16+
public class HelpCommandParser implements Parser<HelpCommand> {
17+
18+
/**
19+
* Parses the given {@code String} of arguments in the context of the HelpCommand
20+
* and returns a HelpCommand object for execution.
21+
* @throws ParseException if the user input does not conform the expected format
22+
*/
23+
public HelpCommand parse(String args) throws ParseException {
24+
String trimmedArgs = args.trim();
25+
if (trimmedArgs.isEmpty()) {
26+
return new HelpCommand("all");
27+
}
28+
String[] helpKeyword = trimmedArgs.split("\\s+");
29+
if (helpKeyword.length > 1) {
30+
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
31+
MESSAGE_TOO_MANY_ARGUMENTS));
32+
}
33+
String helpArgument = helpKeyword[0].toLowerCase();
34+
if (!Arrays.asList(ALLOWED_ARGUMENTS).contains(helpArgument)) {
35+
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
36+
MESSAGE_WRONG_ARGUMENT));
37+
}
38+
return new HelpCommand(helpArgument);
39+
}
40+
}

src/main/java/seedu/clinic/ui/HelpWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
public class HelpWindow extends UiPart<Stage> {
1717

18-
public static final String USERGUIDE_URL = "https://se-education.org/addressbook-level3/UserGuide.html";
18+
public static final String USERGUIDE_URL = "https://ay2021s1-cs2103-w14-4.github.io/tp/UserGuide.html";
1919
public static final String HELP_MESSAGE = "Refer to the user guide: " + USERGUIDE_URL;
2020

2121
private static final Logger logger = LogsCenter.getLogger(HelpWindow.class);

src/main/resources/view/ResultDisplay.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
<StackPane fx:id="placeHolder" styleClass="pane-with-border" xmlns="http://javafx.com/javafx/8"
77
xmlns:fx="http://javafx.com/fxml/1">
8-
<TextArea fx:id="resultDisplay" editable="false" styleClass="result-display"/>
8+
<TextArea fx:id="resultDisplay" editable="false" styleClass="result-display" wrapText="true"/>
99
</StackPane>

0 commit comments

Comments
 (0)