From 80a541e0d7edc45d153f5b0b343cc0e2eb94e13b Mon Sep 17 00:00:00 2001 From: hingen <1627313-hingen@users.noreply.gitlab.com> Date: Fri, 31 Mar 2023 08:23:55 +0800 Subject: [PATCH] Change /overwrite prefix to be a flag --- .../seedu/address/commons/core/Messages.java | 4 ++-- .../address/logic/commands/ExportCommand.java | 7 ++++--- .../address/logic/commands/ImportCommand.java | 19 ++++++++++++------- .../logic/parser/ExportCommandParser.java | 8 +------- .../logic/parser/ImportCommandParser.java | 7 +------ .../logic/parser/ExportCommandParserTest.java | 2 +- .../logic/parser/ImportCommandParserTest.java | 4 ++-- 7 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index b7b000a71be..d04f14017d0 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -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"; diff --git a/src/main/java/seedu/address/logic/commands/ExportCommand.java b/src/main/java/seedu/address/logic/commands/ExportCommand.java index 441093d3a5b..7a8e0060a98 100644 --- a/src/main/java/seedu/address/logic/commands/ExportCommand.java +++ b/src/main/java/seedu/address/logic/commands/ExportCommand.java @@ -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; @@ -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; diff --git a/src/main/java/seedu/address/logic/commands/ImportCommand.java b/src/main/java/seedu/address/logic/commands/ImportCommand.java index 34744c8202d..3c0b724c955 100644 --- a/src/main/java/seedu/address/logic/commands/ImportCommand.java +++ b/src/main/java/seedu/address/logic/commands/ImportCommand.java @@ -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; @@ -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"; @@ -87,4 +93,3 @@ public boolean equals(Object other) { && (isImportingAllModules == otherCommand.isImportingAllModules); } } - diff --git a/src/main/java/seedu/address/logic/parser/ExportCommandParser.java b/src/main/java/seedu/address/logic/parser/ExportCommandParser.java index fda764ea1bc..fd24bd8f02b 100644 --- a/src/main/java/seedu/address/logic/parser/ExportCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ExportCommandParser.java @@ -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(); diff --git a/src/main/java/seedu/address/logic/parser/ImportCommandParser.java b/src/main/java/seedu/address/logic/parser/ImportCommandParser.java index afe667282ea..26948affa80 100644 --- a/src/main/java/seedu/address/logic/parser/ImportCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ImportCommandParser.java @@ -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 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()) { diff --git a/src/test/java/seedu/address/logic/parser/ExportCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ExportCommandParserTest.java index 823a8366a13..0d07471bd43 100644 --- a/src/test/java/seedu/address/logic/parser/ExportCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ExportCommandParserTest.java @@ -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)); } diff --git a/src/test/java/seedu/address/logic/parser/ImportCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ImportCommandParserTest.java index 50dec7c15ad..4772b990fef 100644 --- a/src/test/java/seedu/address/logic/parser/ImportCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ImportCommandParserTest.java @@ -44,7 +44,7 @@ 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)); @@ -52,7 +52,7 @@ public void parseCommand_overwriteModule_successful() throws ParseException { @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);