Skip to content

Commit

Permalink
Merge pull request #202 from NereusWB922/200-help-option
Browse files Browse the repository at this point in the history
Add help option for all commands
  • Loading branch information
NgChunMan authored Oct 31, 2023
2 parents 8cabe22 + 0a671f3 commit 11ba70d
Show file tree
Hide file tree
Showing 27 changed files with 302 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public class ChangeDirectoryCommand extends Command {
public static final String MESSAGE_PATH_NOT_FOUND = "Path does not exist in ProfBook.";

public static final String MESSAGE_USAGE = COMMAND_WORD + " [destination path]";
public static final ChangeDirectoryCommand HELP_MESSAGE = new ChangeDirectoryCommand();

private final AbsolutePath dest;
private final boolean isHelp;

/**
* Constructs a {@code MoveStudentToGroupCommand} with the specified source and destination paths.
Expand All @@ -30,6 +32,12 @@ public class ChangeDirectoryCommand extends Command {
public ChangeDirectoryCommand(AbsolutePath dest) {
requireAllNonNull(dest);
this.dest = dest;
this.isHelp = false;
}

private ChangeDirectoryCommand() {
this.dest = null;
isHelp = true;
}

/**
Expand All @@ -41,6 +49,10 @@ public ChangeDirectoryCommand(AbsolutePath dest) {
*/
@Override
public CommandResult execute(Model model) throws CommandException {
if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

if (!model.hasPath(dest)) {
throw new CommandException(MESSAGE_PATH_NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public class CreateDeadlineCommand extends Command {
public static final String MESSAGE_INVALID_PATH_FOR_ALL_STU = "AllStu flag is only allowed for root and group path";
public static final String MESSAGE_INVALID_PATH_FOR_ALL_GROUP = "AllGrp flag is only allowed for root path";
public static final String MESSAGE_ALL_CHILDREN_HAVE_TASK = "All %1$ss already have the task.";
public static final CreateDeadlineCommand HELP_MESSAGE = new CreateDeadlineCommand();

private final AbsolutePath path;
private final Deadline deadline;
private Category category;
private final Category category;
private final boolean isHelp;

/**
* Creates an CreateDeadlineCommand to add the Deadline Task for a specified {@code Student} or {@code Group}
Expand All @@ -65,6 +67,14 @@ public CreateDeadlineCommand(AbsolutePath path, Deadline deadline, Category cate
this.path = path;
this.deadline = deadline;
this.category = category;
this.isHelp = false;
}

private CreateDeadlineCommand() {
this.path = null;
this.deadline = null;
this.category = null;
this.isHelp = true;
}

/**
Expand All @@ -75,6 +85,11 @@ public CreateDeadlineCommand(AbsolutePath path, Deadline deadline, Category cate
*/
@Override
public CommandResult execute(Model model) throws CommandException {

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

// Check path exists in ProfBook
if (!model.hasPath(path)) {
throw new CommandException(MESSAGE_PATH_NOT_FOUND);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/logic/commands/CreateGroupCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ public class CreateGroupCommand extends Command {
"GroupId %1$s has already been used by the group: %2$s";
public static final String MESSAGE_SUCCESS = "New group added: %1$s";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": group";
public static final CreateGroupCommand HELP_MESSAGE = new CreateGroupCommand();

private final AbsolutePath dest;
private final Group group;
private final boolean isHelp;

/**
* Constructs a {@code CreateGroupCommand} with the specified absolute path and group details.
Expand All @@ -35,6 +38,13 @@ public CreateGroupCommand(AbsolutePath dest, Group group) {
requireAllNonNull(dest, group);
this.dest = dest;
this.group = group;
this.isHelp = false;
}

private CreateGroupCommand() {
this.isHelp = true;
this.dest = null;
this.group = null;
}

/**
Expand All @@ -48,6 +58,10 @@ public CreateGroupCommand(AbsolutePath dest, Group group) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

ChildOperation<Group> rootOperation = model.rootChildOperation();

// Check duplicate group id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public class CreateStudentCommand extends Command {
public static final String MESSAGE_INVALID_PATH = "Path provided should be a valid student path";
public static final String MESSAGE_UNSUPPORTED_PATH_OPERATION = "Path operation is not supported";
public static final String MESSAGE_GROUP_NOT_FOUND = "Group %1$s does not exist in ProfBook";
public static final CreateStudentCommand HELP_MESSAGE = new CreateStudentCommand();

private final AbsolutePath path;
private final Student student;
private final boolean isHelp;

/**
* Creates an CreateStudentCommand to add the specified {@code Student}
Expand All @@ -52,6 +54,13 @@ public CreateStudentCommand(AbsolutePath path, Student student) {
requireAllNonNull(path, student);
this.path = path;
this.student = student;
this.isHelp = false;
}

private CreateStudentCommand() {
this.path = null;
this.student = null;
this.isHelp = true;
}

/**
Expand All @@ -64,6 +73,10 @@ public CreateStudentCommand(AbsolutePath path, Student student) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

if (!path.isStudentDirectory()) {
throw new CommandException(MESSAGE_INVALID_PATH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public class CreateTodoCommand extends Command {
public static final String MESSAGE_INVALID_PATH_FOR_ALL_GROUP = "AllGrp flag is only allowed for root path";
public static final String MESSAGE_ALL_CHILDREN_HAVE_TASK = "All %1$ss already have the task.";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": student";
public static final CreateTodoCommand HELP_MESSAGE = new CreateTodoCommand();

private final AbsolutePath target;
private final ToDo todo;
private Category category;
private final Category category;
private final boolean isHelp;

/**
* Constructs a {@code CreateTodoCommand} with the specified absolute path and "ToDo" task details.
Expand All @@ -62,6 +64,14 @@ public CreateTodoCommand(AbsolutePath target, ToDo todo, Category category) {
this.target = target;
this.todo = todo;
this.category = category;
this.isHelp = false;
}

private CreateTodoCommand() {
this.target = null;
this.todo = null;
this.category = null;
this.isHelp = true;
}

/**
Expand All @@ -74,6 +84,11 @@ public CreateTodoCommand(AbsolutePath target, ToDo todo, Category category) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

// Check path exists in ProfBook
if (!model.hasPath(target)) {
throw new CommandException(MESSAGE_PATH_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ public class DeleteForStudentsAndGroupsCommand extends Command {
public static final String MESSAGE_NO_SUCH_STUDENT_OR_GROUP = "There is no such student or group to delete";
public static final String MESSAGE_DELETE_CURRENT_PATH = "Current path cannot be deleted";
public static final String MESSAGE_DELETE_DISPLAY_PATH = "Current display path cannot be deleted.";
protected Student stu;
protected Group grp;
public static final DeleteForStudentsAndGroupsCommand HELP_MESSAGE = new DeleteForStudentsAndGroupsCommand();

private final AbsolutePath toBeDeleted;
private final boolean isHelp;

/**
* Creates an DeleteForStudentsAndGroupsCommand to specified {@code Student} or {@code Group}
*/
public DeleteForStudentsAndGroupsCommand(AbsolutePath toBeDeleted) { //path will specify which grp/student
requireNonNull(toBeDeleted);
this.toBeDeleted = toBeDeleted;
this.isHelp = false;
}

private DeleteForStudentsAndGroupsCommand() {
this.toBeDeleted = null;
this.isHelp = true;
}

/**
Expand All @@ -61,6 +68,10 @@ public DeleteForStudentsAndGroupsCommand(AbsolutePath toBeDeleted) { //path will
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

if (toBeDeleted.isRootDirectory()) {
throw new CommandException(MESSAGE_INCORRECT_DIRECTORY_ERROR);
}
Expand All @@ -86,7 +97,7 @@ public CommandResult execute(Model model) throws CommandException {
if (!target.hasChild(studentId)) {
throw new CommandException(MESSAGE_NO_SUCH_STUDENT_OR_GROUP);
}
stu = target.getChild(studentId);
Student stu = target.getChild(studentId);
target.deleteChild(studentId);
model.updateList();
return new CommandResult(String.format(MESSAGE_SUCCESS_FOR_STUDENT, Messages.format(stu)));
Expand All @@ -98,7 +109,7 @@ public CommandResult execute(Model model) throws CommandException {
if (!target.hasChild(groupId)) {
throw new CommandException(MESSAGE_NO_SUCH_STUDENT_OR_GROUP);
}
grp = target.getChild(groupId);
Group grp = target.getChild(groupId);
target.deleteChild(groupId);
model.updateList();
return new CommandResult(String.format(MESSAGE_SUCCESS_FOR_GROUP, Messages.format(grp)));
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteTaskCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,35 @@ public class DeleteTaskCommand extends Command {
public static final String MESSAGE_TASK_LIST_NOT_SHOWN = "Current display panel is not displaying task list.";
public static final String MESSAGE_INVALID_INDEX = "The task list provided is invalid.";
public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted task: %1$s";
public static final DeleteTaskCommand HELP_MESSAGE = new DeleteTaskCommand();

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

private final Index targetIndex;
private final boolean isHelp;

/**
* Construct a DeleteTaskCommand instance with target index.
*/
public DeleteTaskCommand(Index targetIndex) {
requireNonNull(targetIndex);
this.targetIndex = targetIndex;
this.isHelp = false;
}

private DeleteTaskCommand() {
this.targetIndex = null;
this.isHelp = true;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

logger.info("Executing delete task command...");

// Check if diplay panel is displaying task list
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ public class EditCommand extends Command {
public static final String MESSAGE_NO_CHANGES_MADE =
"The value(s) you provided is the same as the current value(s). No changes have been made.";

private final AbsolutePath target;

private EditGroupDescriptor editGroupDescriptor;
public static final EditCommand HELP_MESSAGE = new EditCommand();

private EditStudentDescriptor editStudentDescriptor;
private final AbsolutePath target;
private final EditGroupDescriptor editGroupDescriptor;
private final EditStudentDescriptor editStudentDescriptor;
private final boolean isHelp;

/**
* Constructs an EditCommand for editing a group's details.
Expand All @@ -95,6 +96,8 @@ public class EditCommand extends Command {
public EditCommand(AbsolutePath target, EditGroupDescriptor editGroupDescriptor) {
this.target = target;
this.editGroupDescriptor = new EditGroupDescriptor(editGroupDescriptor);
this.editStudentDescriptor = null;
this.isHelp = false;
}

/**
Expand All @@ -106,6 +109,15 @@ public EditCommand(AbsolutePath target, EditGroupDescriptor editGroupDescriptor)
public EditCommand(AbsolutePath target, EditStudentDescriptor editStudentDescriptor) {
this.target = target;
this.editStudentDescriptor = new EditStudentDescriptor(editStudentDescriptor);
this.editGroupDescriptor = null;
this.isHelp = false;
}

private EditCommand() {
this.target = null;
this.editGroupDescriptor = null;
this.editStudentDescriptor = null;
this.isHelp = true;
}

/**
Expand All @@ -119,6 +131,10 @@ public EditCommand(AbsolutePath target, EditStudentDescriptor editStudentDescrip
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (this.isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

// Check path exists in ProfBook
if (!model.hasPath(target)) {
throw new CommandException(MESSAGE_NO_SUCH_PATH);
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/seedu/address/logic/commands/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@
public class MarkCommand extends Command {

public static final String COMMAND_WORD = "mark";

public static final String MESSAGE_INCORRECT_STATE = "The current model is not showing task list.";

public static final String MESSAGE_INVALID_INDEX = "The task index provided is invalid.";

public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked task: %1$s";

public static final String MESSAGE_USAGE = COMMAND_WORD + " [task index]";
public static final MarkCommand HELP_MESSAGE = new MarkCommand();

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

private final Index index;
private final boolean isHelp;

/**
* Constructs a MarkCommand with the specified task index to be marked.
Expand All @@ -42,6 +39,12 @@ public class MarkCommand extends Command {
public MarkCommand(Index index) {
requireNonNull(index);
this.index = index;
this.isHelp = false;
}

private MarkCommand() {
this.index = null;
this.isHelp = true;
}

/**
Expand All @@ -55,6 +58,10 @@ public MarkCommand(Index index) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (isHelp) {
return new CommandResult(MESSAGE_USAGE);
}

logger.info("Executing mark task command...");

if (!model.isShowTaskList()) {
Expand Down
Loading

0 comments on commit 11ba70d

Please sign in to comment.