summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-08-27 09:44:38 +0200
committer zaaarf <zaaarf@proton.me>2023-08-27 09:44:38 +0200
commitbbea72ed47ccde96a4200382e4ea67e277cd5378 (patch)
treedc32162de6fe42fae720d9a316a300987db1e9d0
parent2a028258cbb54fd115dd12a151efdef136b624aa (diff)
feat: handling custom args
-rw-r--r--src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java30
-rw-r--r--src/main/java/ftbsc/lll/mapper/writer/impl/TinyV2Writer.java2
2 files changed, 22 insertions, 10 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java b/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java
index 2cc8007..a884b3a 100644
--- a/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java
+++ b/src/main/java/ftbsc/lll/mapper/writer/MappingWriter.java
@@ -8,10 +8,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
+import java.util.*;
/**
* Writes a mapping to a certain format.
@@ -31,9 +28,24 @@ public class MappingWriter {
CommandLine cmdLine = parser.parse(options, args);
args = cmdLine.getArgs();
- if(args.length != 3) {
+ //separate normal args from custom args
+ int cursor;
+ for(cursor = 0; cursor < args.length; cursor++)
+ if(args[cursor].equals("-a"))
+ break;
+ String[] customArgs;
+ if(cursor != args.length) {
+ int len = args.length - cursor - 1;
+ customArgs = new String[len];
+ System.arraycopy(args, cursor + 1, customArgs, 0, len);
+ String[] newArgs = new String[cursor];
+ System.arraycopy(args, 0, newArgs, 0, cursor);
+ args = newArgs;
+ } else customArgs = new String[0];
+
+ if(args.length < 4) {
System.err.println("Bad argument count!");
- System.err.println("java -jar mapping-writer.jar [-r] <location> <format> <output>");
+ System.err.println("java -jar mapping-writer.jar [-r] <location> <format> <output> [-a <custom args]");
return;
}
@@ -60,18 +72,18 @@ public class MappingWriter {
File targetFile = new File(args[2]);
if(!targetFile.createNewFile()) {
- System.out.println("File already exists!");
+ System.err.println("File already exists!");
return;
}
if(!targetFile.canWrite()) {
- System.out.println("Failed to write to file: access denied.");
+ System.err.println("Failed to write to file: access denied.");
return;
}
//call the writer
PrintWriter printWriter = new PrintWriter(new FileWriter(targetFile));
- writer.write(mapper, printWriter);
+ writer.write(mapper, printWriter, customArgs);
printWriter.close();
}
}
diff --git a/src/main/java/ftbsc/lll/mapper/writer/impl/TinyV2Writer.java b/src/main/java/ftbsc/lll/mapper/writer/impl/TinyV2Writer.java
index fb233c3..8dc955c 100644
--- a/src/main/java/ftbsc/lll/mapper/writer/impl/TinyV2Writer.java
+++ b/src/main/java/ftbsc/lll/mapper/writer/impl/TinyV2Writer.java
@@ -18,7 +18,7 @@ public class TinyV2Writer implements IWriter {
@Override
public void write(IMapper mapper, PrintWriter writer, String... args) {
- writer.printf("tiny\t2\t0\t%s\t%s", args[0], args[1]); //TODO namespace naming support
+ writer.printf("tiny\t2\t0\t%s\t%s", args[0], args[1]);
mapper.getRawMappings().forEach((name, data) -> {
writer.printf("c\t%s\t%s\n", name, data.nameMapped);
data.getFields().forEach((fieldName, fieldData) ->