From 32ea510f10abbed2a07713430e8e0eb44a91829b Mon Sep 17 00:00:00 2001 From: zaaarf Date: Fri, 1 Sep 2023 12:34:10 +0200 Subject: feat: -o flag --- src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java') diff --git a/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java b/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java index 188532b..db1d219 100644 --- a/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java +++ b/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java @@ -23,7 +23,8 @@ public class MappingWriter { */ public static void main(String[] args) throws IOException, ParseException { Options options = new Options() - .addOption("r", "reverse", false, "Writes down inverted mappings"); + .addOption("r", "reverse", false, "Writes down inverted mappings") + .addOption("o", "overwrite", false, "Overwrites the file even if it exists"); DefaultParser parser = new DefaultParser(); CommandLine cmdLine = parser.parse(options, args); args = cmdLine.getArgs(); @@ -70,9 +71,11 @@ public class MappingWriter { //now for the file File targetFile = new File(args[2]); - if(!targetFile.createNewFile()) { - System.err.println("File already exists!"); - return; + if(!cmdLine.hasOption("overwrite") || !targetFile.exists()) { + if(!targetFile.createNewFile()) { + System.err.println("File already exists!"); + return; + } } if(!targetFile.canWrite()) { -- cgit v1.2.3-56-ga3b1