Skip to content

Commit

Permalink
Add help command
Browse files Browse the repository at this point in the history
  • Loading branch information
YFshadaow committed Nov 1, 2023
1 parent 1642706 commit 2ecb578
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 19 deletions.
159 changes: 159 additions & 0 deletions src/main/java/seedu/financialplanner/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package seedu.financialplanner.commands;

import seedu.financialplanner.utils.Ui;

import java.util.ArrayList;

import static seedu.financialplanner.utils.Parser.ADD_CASHFLOW_COMMAND;
import static seedu.financialplanner.utils.Parser.ADD_REMINDER_COMMAND;
import static seedu.financialplanner.utils.Parser.ADD_STOCK_COMMAND;
import static seedu.financialplanner.utils.Parser.BALANCE_COMMAND;
import static seedu.financialplanner.utils.Parser.BUDGET_COMMAND;
import static seedu.financialplanner.utils.Parser.DELETE_CASHFLOW_COMMAND;
import static seedu.financialplanner.utils.Parser.DELETE_STOCK_COMMAND;
import static seedu.financialplanner.utils.Parser.EXIT_COMMAND;
import static seedu.financialplanner.utils.Parser.FIND_COMMAND;
import static seedu.financialplanner.utils.Parser.HELP_COMMAND;
import static seedu.financialplanner.utils.Parser.LIST_COMMAND;
import static seedu.financialplanner.utils.Parser.OVERVIEW_COMMAND;
import static seedu.financialplanner.utils.Parser.SET_GOAL_COMMAND;
import static seedu.financialplanner.utils.Parser.VISUALIZATION_COMMAND;
import static seedu.financialplanner.utils.Parser.WATCHLIST_COMMAND;

public class HelpCommand extends Command {
private static final String EXIT_COMMAND_USAGE =
"exit";
private static final String WATCHLIST_COMMAND_USAGE =
"watchlist";
private static final String ADD_CASHFLOW_COMMAND_USAGE =
"add <income/expense> </a AMOUNT> [/t TYPE] [/r RECURRENCE INTERVAL IN DAYS] [/d DESCRIPTION]";

private static final String DELETE_CASHFLOW_COMMAND_USAGE =
"delete [income/expense] <INDEX>";

private static final String ADD_STOCK_COMMAND_USAGE =
"addstock </s STOCK CODE>";

private static final String DELETE_STOCK_COMMAND_USAGE =
"deletestock </s STOCK CODE>";

private static final String FIND_COMMAND_USAGE =
"find <KEYWORD>";

private static final String BUDGET_COMMAND_USAGE =
"budget set </b BUDGET>"
+ "\n " + "budget update </b BUDGET>"
+ "\n " + "budget delete"
+ "\n " + "budget reset"
+ "\n " + "budget view";
private static final String VISUALIZATION_COMMAND_USAGE =
"vis </t TYPE> </c pie/bar/radar>";

private static final String OVERVIEW_COMMAND_USAGE =
"overview";
private static final String ADD_REMINDER_COMMAND_USAGE =
"addreminder </t TYPE> </d DATE>";

private static final String LIST_COMMAND_USAGE =
"list [income/expense]";

private static final String SET_GOAL_COMMAND_USAGE =
"set </g AMOUNT> </l LABEL>";

private static final String BALANCE_COMMAND_USAGE =
"balance";

private static final String HELP_COMMAND_USAGE =
"help [COMMAND]";

private static final String HELP_MESSAGE_GENERAL =
"<> denotes required arguments, [] denotes optional arguments"
+ "\n" + "Here are the available commands:"
+ "\n " + EXIT_COMMAND_USAGE
+ "\n " + WATCHLIST_COMMAND_USAGE
+ "\n " + ADD_CASHFLOW_COMMAND_USAGE
+ "\n " + DELETE_CASHFLOW_COMMAND_USAGE
+ "\n " + ADD_STOCK_COMMAND_USAGE
+ "\n " + DELETE_STOCK_COMMAND_USAGE
+ "\n " + FIND_COMMAND_USAGE
+ "\n " + BUDGET_COMMAND_USAGE
+ "\n " + VISUALIZATION_COMMAND_USAGE
+ "\n " + OVERVIEW_COMMAND_USAGE
+ "\n " + ADD_REMINDER_COMMAND_USAGE
+ "\n " + LIST_COMMAND_USAGE
+ "\n " + SET_GOAL_COMMAND_USAGE
+ "\n " + BALANCE_COMMAND_USAGE
+ "\n " + HELP_COMMAND_USAGE;
private final String commandName;

public HelpCommand(RawCommand rawCommand) {
if (!rawCommand.extraArgs.isEmpty()) {
String unknownExtraArgument = new ArrayList<>(rawCommand.extraArgs.keySet()).get(0);
throw new IllegalArgumentException(String.format("Unknown extra argument: %s", unknownExtraArgument));
}
if (rawCommand.args.isEmpty()) {
commandName = null;
} else if (rawCommand.args.size() == 1) {
commandName = rawCommand.args.get(0);
} else {
throw new IllegalArgumentException("Unknown arguments, type help for help");
}
}

@Override
public void execute() throws Exception {
if (commandName == null) {
Ui.getInstance().showMessage(HELP_MESSAGE_GENERAL);
return;
}
switch (commandName) {
case EXIT_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + EXIT_COMMAND_USAGE);
break;
case WATCHLIST_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + WATCHLIST_COMMAND_USAGE);
break;
case ADD_CASHFLOW_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + ADD_CASHFLOW_COMMAND_USAGE);
break;
case DELETE_CASHFLOW_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + DELETE_CASHFLOW_COMMAND_USAGE);
break;
case ADD_STOCK_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + ADD_STOCK_COMMAND_USAGE);
break;
case DELETE_STOCK_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + DELETE_STOCK_COMMAND_USAGE);
break;
case FIND_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + FIND_COMMAND_USAGE);
break;
case BUDGET_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + BUDGET_COMMAND_USAGE);
break;
case VISUALIZATION_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + VISUALIZATION_COMMAND_USAGE);
break;
case OVERVIEW_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + OVERVIEW_COMMAND_USAGE);
break;
case ADD_REMINDER_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + ADD_REMINDER_COMMAND_USAGE);
break;
case LIST_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + LIST_COMMAND_USAGE);
break;
case SET_GOAL_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + SET_GOAL_COMMAND_USAGE);
break;
case BALANCE_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + BALANCE_COMMAND_USAGE);
break;
case HELP_COMMAND:
Ui.getInstance().showMessage("Usage:\n " + HELP_COMMAND_USAGE);
break;
default:
Ui.getInstance().showMessage("Unknown command, type help for help");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public InvalidCommand() {
*/
@Override
public void execute() {
Ui.getInstance().showMessage("Unknown command. Please try again.");
Ui.getInstance().showMessage("Unknown command. Type help for help");
}
}
33 changes: 19 additions & 14 deletions src/main/java/seedu/financialplanner/utils/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import seedu.financialplanner.commands.Command;
import seedu.financialplanner.commands.AddStockCommand;
import seedu.financialplanner.commands.HelpCommand;
import seedu.financialplanner.commands.OverviewCommand;
import seedu.financialplanner.commands.AddCashflowCommand;
import seedu.financialplanner.commands.DeleteCashflowCommand;
Expand All @@ -27,20 +28,22 @@
import java.util.Map;

public class Parser {
private static final String EXIT_COMMAND = "exit";
private static final String WATCHLIST_COMMAND = "watchlist";
private static final String ADD_CASHFLOW_COMMAND = "add";
private static final String DELETE_CASHFLOW_COMMAND = "delete";
private static final String ADD_STOCK_COMMAND = "addstock";
private static final String DELETE_STOCK_COMMAND = "deletestock";
private static final String FIND_COMMAND = "find";
private static final String OVERVIEW_COMMAND = "overview";
private static final String BUDGET_COMMAND = "budget";
private static final String VISUALIZATION_COMMAND = "vis";
private static final String ADD_REMINDER_COMMAND = "addreminder";
private static final String LIST_COMMAND = "list";
private static final String SET_GOAL_COMMAND = "set";
private static final String BALANCE_COMMAND = "balance";
public static final String EXIT_COMMAND = "exit";
public static final String WATCHLIST_COMMAND = "watchlist";
public static final String ADD_CASHFLOW_COMMAND = "add";
public static final String DELETE_CASHFLOW_COMMAND = "delete";
public static final String ADD_STOCK_COMMAND = "addstock";
public static final String DELETE_STOCK_COMMAND = "deletestock";
public static final String FIND_COMMAND = "find";
public static final String OVERVIEW_COMMAND = "overview";
public static final String BUDGET_COMMAND = "budget";
public static final String VISUALIZATION_COMMAND = "vis";
public static final String ADD_REMINDER_COMMAND = "addreminder";
public static final String LIST_COMMAND = "list";
public static final String SET_GOAL_COMMAND = "set";
public static final String BALANCE_COMMAND = "balance";

public static final String HELP_COMMAND = "help";

public static Command parseCommand(String input) throws FinancialPlannerException {
RawCommand rawCommand = parseRawCommand(input);
Expand Down Expand Up @@ -77,6 +80,8 @@ public static Command parseCommand(RawCommand rawCommand) throws FinancialPlanne
return new SetGoalCommand(rawCommand);
case BALANCE_COMMAND:
return new BalanceCommand(rawCommand);
case HELP_COMMAND:
return new HelpCommand(rawCommand);
default:
return new InvalidCommand();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/financialplanner/utils/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Ui {
private static final String GREEN = "\u001B[32m";
private static final String RESET = "\u001B[0m";
private static final String YELLOW = "\u001B[33m";
private Scanner Scanner = new Scanner(System.in);
private Scanner scanner = new Scanner(System.in);
private Ui() {
}

Expand All @@ -38,11 +38,11 @@ public static void printCorruptedFileError(String message) {
}

public Scanner getScanner() {
return Scanner;
return scanner;
}

public void setScanner(Scanner scanner) {
this.Scanner = scanner;
this.scanner = scanner;
}

public void showMessage(String message) {
Expand All @@ -59,7 +59,7 @@ public void exitMessage() {
}

public String input() {
return Scanner.nextLine().trim();
return scanner.nextLine().trim();
}

public void printWatchListHeader() {
Expand Down

0 comments on commit 2ecb578

Please sign in to comment.