Skip to content

Commit

Permalink
Merge pull request #75 from yakultbottle/helpFix
Browse files Browse the repository at this point in the history
Bug Fixes for Help Command: Logging and Parser Corrections
  • Loading branch information
yakultbottle authored Oct 14, 2024
2 parents eb94982 + 636ebda commit c72b0d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
35 changes: 13 additions & 22 deletions src/main/java/seedu/pill/command/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import seedu.pill.exceptions.PillException;
import seedu.pill.util.ItemList;
import seedu.pill.util.Storage;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -13,21 +15,10 @@ public class HelpCommand extends Command {
private String commandName;
private boolean verbose;

public HelpCommand() {
this.commandName = null;
this.verbose = false;
logger.info("Created HelpCommand with no specific command");
}

public HelpCommand(String commandName) {
this.commandName = commandName;
this.verbose = false;
logger.info("Created HelpCommand for command: " + commandName);
}

public HelpCommand(String commandName, boolean verbose) {
this.commandName = commandName;
this.verbose = verbose;
logger.setLevel(Level.OFF);
logger.info("Created HelpCommand for command: " + commandName + " with verbose mode: " + verbose);
}

Expand Down Expand Up @@ -62,7 +53,7 @@ private void showGeneralHelp() {
System.out.println(" delete - Deletes an item from the list");
System.out.println(" edit - Edits quantity of an existing item in the list");
System.out.println(" list - Lists all items");
System.out.println(" quit - Exits the program");
System.out.println(" exit - Exits the program");
System.out.println("Type 'help <command>' for more information on a specific command.");
System.out.println("Add '-v' after the command for verbose output with examples.");
}
Expand Down Expand Up @@ -91,12 +82,12 @@ private void showSpecificHelp(String command) {
case "list":
showListHelp();
break;
case "quit":
showQuitHelp();
case "exit":
showExitHelp();
break;
default:
System.out.println("Unknown command: " + command);
System.out.println("Available commands: help, add, delete, edit, list, quit");
System.out.println("Available commands: help, add, delete, edit, list, exit");
System.out.println("Type 'help <command>' for more information on a specific command.");
}
}
Expand Down Expand Up @@ -184,16 +175,16 @@ private void showListHelp() {
}

/**
* Prints detailed information about the 'quit' command.
* Prints detailed information about the 'exit' command.
*/
private void showQuitHelp() {
logger.fine("Showing help information for 'quit' command");
private void showExitHelp() {
logger.fine("Showing help information for 'exit' command");

System.out.println("quit: Exits the program.");
System.out.println("exit: Exits the program.");
if (verbose) {
System.out.println("Usage: quit");
System.out.println("Usage: exit");
System.out.println("\nExample:");
System.out.println(" quit");
System.out.println(" exit");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/pill/util/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void parseCommand(String input) throws PillException {
new FindCommand(argument).execute(this.items, this.storage);
break;
case "help":
new HelpCommand().execute(this.items, this.storage);
boolean flag = quantityStr.equals("-v");
new HelpCommand(argument, flag).execute(this.items, this.storage);
break;
case "list":
new ListCommand().execute(this.items, this.storage);
Expand Down

0 comments on commit c72b0d6

Please sign in to comment.