Skip to content

Commit

Permalink
Merge pull request #230 from hingen/standardise_messages
Browse files Browse the repository at this point in the history
Change /overwrite prefix to be a flag
  • Loading branch information
shaowi authored Mar 31, 2023
2 parents 07eaa9d + 80a541e commit 81acb86
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public class Messages {
public static final String MESSAGE_CONFLICTING_ARGS = "The arguments %1$s and %2$s cannot both be specified";
public static final String MESSAGE_EMPTY_MODULE = "No module is provided";
public static final String MESSAGE_ARCHIVE_FILE_ALREADY_EXIST = "File already exist. If you want to "
+ "overwrite this file, insert /overwrite true in the command";
+ "overwrite this file, insert /overwrite in the command";
public static final String MESSAGE_FILE_DOES_NOT_EXIST = "Either the file does not exist, or it was corrupted/ of"
+ " a wrong format";
public static final String MESSAGE_MODULE_ALREADY_EXIST_IN_TRACKER = "%1$s already exist in tracker. If you want "
+ "to overwrite data in this module, insert /overwrite true in the command";
+ "to overwrite data in this module, insert /overwrite in the command";
public static final String MESSAGE_MODULE_DOES_NOT_EXIST_IN_ARCHIVE = "%1$s not found in this file";
public static final String MESSAGE_EMPTY_TIMESTAMP_COMMENT = "No comment is provided";
public static final String MESSAGE_TIMESTAMP_COMMENT_DOES_NOT_EXIST = "Comment(s) %1$s does not exist";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/seedu/address/logic/commands/ExportCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_OVERWRITE;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -16,14 +17,14 @@
public class ExportCommand extends Command {
public static final String COMMAND_WORD = "export";
public static final String MESSAGE_USAGE = "\n" + COMMAND_WORD + ":\n"
+ "(1) Archive all modules currently in Le Tracker to a new file. File must be of JSON format\n"
+ "(1) Archive all modules currently in Le Tracker to a new file.\n"
+ "Parameter: "
+ "{file_name}\n"
+ "Example: " + COMMAND_WORD + " hello.json\n\n"
+ "(2) Archive all modules currently in Le Tracker to an existing file.\n"
+ "Parameter: "
+ "{file_name}\n"
+ "Example: " + COMMAND_WORD + " hello.json /overwrite true \n\n";
+ "{file_name} " + PREFIX_OVERWRITE + "\n"
+ "Example: " + COMMAND_WORD + " hello.json " + PREFIX_OVERWRITE;
public static final String MESSAGE_SUCCESS = "All modules archived to %1$s";

private final String fileName;
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/seedu/address/logic/commands/ImportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_OVERWRITE;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -22,20 +23,25 @@ public class ImportCommand extends Command {
//TODO: CHANGE THIS

public static final String MESSAGE_USAGE = "\n" + COMMAND_WORD + ":\n"
+ "(1) Import all modules in archive file\n"
+ "(1) Import all modules from archive file.\n"
+ "Parameter: "
+ "{file_name}\n"
+ "Example: " + COMMAND_WORD + " hello.json\n\n"
+ "(2) Import specific modules in archive file, no similar modules in Le Tracker\n"
+ "(2) Import specific modules from archive file.\n"
+ "Parameter: "
+ "{file_name} "
+ PREFIX_MODULE + " {module_1}[, {module_2}[, ...]]\n"
+ "Example: " + COMMAND_WORD + " hello.json /mod EG2310, EG1311 \n\n"
+ "(2) Import specific modules in archive file, overwrite similar modules in Le Tracker\n"
+ "Example: " + COMMAND_WORD + " hello.json " + PREFIX_MODULE + " EG2310, EG1311\n\n"
+ "(3) Import all modules from archive file, overwriting similar modules in Le Tracker.\n"
+ "Parameter: "
+ "{file_name} " + PREFIX_OVERWRITE + "\n"
+ "Example: " + COMMAND_WORD + " hello.json " + PREFIX_OVERWRITE + "\n\n"
+ "(4) Import specific modules from archive file, overwriting similar modules in Le Tracker.\n"
+ "Parameter: "
+ "{file_name} "
+ PREFIX_MODULE + " {module_1}[, {module_2}[, ...]]\n"
+ "Example: " + COMMAND_WORD + " hello.json /mod EG2310, EG1311 /overwrite true \n\n";
+ PREFIX_MODULE + " {module_1}[, {module_2}[, ...]] "
+ PREFIX_OVERWRITE + "\n"
+ "Example: " + COMMAND_WORD + " hello.json " + PREFIX_MODULE + " EG2310, EG1311 " + PREFIX_OVERWRITE;

public static final String MESSAGE_SUCCESS = "Modules %1$s imported to Le Tracker";

Expand Down Expand Up @@ -87,4 +93,3 @@ public boolean equals(Object other) {
&& (isImportingAllModules == otherCommand.isImportingAllModules);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ public class ExportCommandParser {

public ExportCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_OVERWRITE);
boolean isOverwritingExistingFile = false;

String overwritingFileArgument = argMultimap.getValue(PREFIX_OVERWRITE).orElse("").trim();

if (overwritingFileArgument.equals("true")) {
isOverwritingExistingFile = true;
}
boolean isOverwritingExistingFile = argMultimap.getValue(PREFIX_OVERWRITE).isPresent();

String fileName = argMultimap.getPreamble().trim();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ public class ImportCommandParser {

public ImportCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_OVERWRITE, PREFIX_MODULE);
boolean isOverwritingExistingModule = false;
boolean isOverwritingExistingModule = argMultimap.getValue(PREFIX_OVERWRITE).isPresent();
boolean isImportingAllModules = false;
Set<ModuleCode> moduleCodeSet = new HashSet<>();

String overwritingFileArgument = argMultimap.getValue(PREFIX_OVERWRITE).orElse("");
if (overwritingFileArgument.equals("true")) {
isOverwritingExistingModule = true;
}

if (!argMultimap.getValue(PREFIX_MODULE).isPresent()) {
isImportingAllModules = true;
} else if (argMultimap.getValue(PREFIX_MODULE).orElse("").isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void parseCommand_doNotOverwriteFile_successful() throws ParseException {

@Test
public void parseCommand_overwriteFileCommand_successful() throws ParseException {
String argument = TEST_FILE + " /overwrite true";
String argument = TEST_FILE + " /overwrite";
ExportCommand expectedCommand = new ExportCommand(TEST_FILE, true);
assertEquals(expectedCommand, parser.parse(argument));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public void parseCommand_doNotOverwriteModule_successful() throws ParseException

@Test
public void parseCommand_overwriteModule_successful() throws ParseException {
String argument = TEST_FILE + " /overwrite true";
String argument = TEST_FILE + " /overwrite";
ImportCommand expectedCommand = new ImportCommand(TEST_FILE, new HashSet<>(),
true, true);
assertEquals(expectedCommand, parser.parse(argument));
}

@Test
public void parseCommand_importSomeModule_successful() throws ParseException {
String argument = TEST_FILE + " " + PREFIX_MODULE + " " + MODULE_1 + ", " + MODULE_2 + " /overwrite true";
String argument = TEST_FILE + " " + PREFIX_MODULE + " " + MODULE_1 + ", " + MODULE_2 + " /overwrite";
ImportCommand expectedCommand = new ImportCommand(TEST_FILE,
new HashSet<>(List.of(new ModuleCode(MODULE_1), new ModuleCode(MODULE_2))),
true, false);
Expand Down

0 comments on commit 81acb86

Please sign in to comment.