feat: -o flag

This commit is contained in:
zaaarf 2023-09-01 12:34:10 +02:00
parent 3e2f0a6bcf
commit 32ea510f10
No known key found for this signature in database
GPG key ID: 6445A5CD15E5B40C

View file

@ -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,10 +71,12 @@ public class MappingWriter {
//now for the file
File targetFile = new File(args[2]);
if(!cmdLine.hasOption("overwrite") || !targetFile.exists()) {
if(!targetFile.createNewFile()) {
System.err.println("File already exists!");
return;
}
}
if(!targetFile.canWrite()) {
System.err.println("Failed to write to file: access denied.");