diff --git a/.idea/libraries/Maven__info_picocli_picocli_3_6_0.xml b/.idea/libraries/Maven__info_picocli_picocli_3_6_0.xml
deleted file mode 100644
index bd18a6cb1..000000000
--- a/.idea/libraries/Maven__info_picocli_picocli_3_6_0.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Maven__info_picocli_picocli_4_2_0.xml b/.idea/libraries/Maven__info_picocli_picocli_4_2_0.xml
new file mode 100644
index 000000000..c6d887975
--- /dev/null
+++ b/.idea/libraries/Maven__info_picocli_picocli_4_2_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/kickc.iml b/kickc.iml
index 8d2201c70..7d0746679 100644
--- a/kickc.iml
+++ b/kickc.iml
@@ -23,6 +23,6 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 1b67bb9a3..15f425f42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,7 +49,7 @@
info.picocli
picocli
- 3.6.0
+ 4.2.0
diff --git a/src/main/java/dk/camelot64/kickc/KickC.java b/src/main/java/dk/camelot64/kickc/KickC.java
index fdc222f8a..9b8ba4b08 100644
--- a/src/main/java/dk/camelot64/kickc/KickC.java
+++ b/src/main/java/dk/camelot64/kickc/KickC.java
@@ -15,10 +15,7 @@ import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
@@ -36,7 +33,7 @@ import java.util.stream.Collectors;
optionListHeading = "%nOptions:%n",
version = "KickC 0.8.1 BETA"
)
-public class KickC implements Callable {
+public class KickC implements Callable {
@CommandLine.Parameters(index = "0", arity = "0..n", description = "The C source files to compile.")
private List cFiles = null;
@@ -59,7 +56,7 @@ public class KickC implements Callable {
@CommandLine.Option(names = {"-d"}, description = "Debug the assembled prg file using C64Debugger. Implicitly assembles the output.")
private boolean debug = false;
- @CommandLine.Option(names = {"-D"}, description = "Define a macro to have a specific value.")
+ @CommandLine.Option(names = {"-D"}, parameterConsumer = DefineConsumer.class, description = "Define macro to value (1 if no value given).")
private Map defines = null;
@CommandLine.Option(names = {"-E"}, description = "Only run the preprocessor. Output is sent to standard out.")
@@ -171,14 +168,16 @@ public class KickC implements Callable {
private String calling = null;
/** Program Exit Code signaling a compile error. */
- public static final int COMPILE_ERROR = 1;
+ public static final int COMPILE_ERROR = CommandLine.ExitCode.SOFTWARE;
public static void main(String[] args) {
- CommandLine.call(new KickC(), args);
+ final CommandLine commandLine = new CommandLine(new KickC());
+ final int exitCode = commandLine.execute(args);
+ System.exit(exitCode);
}
@Override
- public Void call() throws Exception {
+ public Integer call() throws Exception {
System.out.println("//--------------------------------------------------");
System.out.println("// " + getVersion() + " by Jesper Gravgaard ");
System.out.println("//--------------------------------------------------");
@@ -195,7 +194,7 @@ public class KickC implements Callable {
supported.append(value.getName()).append(" ");
}
System.err.println(supported);
- System.exit(COMPILE_ERROR);
+ return COMPILE_ERROR;
}
compiler.setTargetPlatform(targetPlatform);
}
@@ -210,7 +209,7 @@ public class KickC implements Callable {
supported.append(value.getName()).append(" ");
}
System.err.println(supported);
- System.exit(COMPILE_ERROR);
+ return COMPILE_ERROR;
}
compiler.setTargetCpu(targetCpu);
}
@@ -325,7 +324,7 @@ public class KickC implements Callable {
compiler.setVariableBuilderConfig(config);
} catch(CompileError e) {
System.err.println(e.getMessage());
- System.exit(COMPILE_ERROR);
+ return COMPILE_ERROR;
}
}
@@ -339,7 +338,7 @@ public class KickC implements Callable {
supported.append(value.getName()).append(" ");
}
System.err.println(supported);
- System.exit(COMPILE_ERROR);
+ return COMPILE_ERROR;
}
compiler.setCallingConvention(callingConvention);
}
@@ -354,7 +353,7 @@ public class KickC implements Callable {
} catch(CompileError e) {
// Print the error and exit with compile error
System.err.println(e.getMessage());
- System.exit(COMPILE_ERROR);
+ return COMPILE_ERROR;
}
return null;
}
@@ -366,7 +365,7 @@ public class KickC implements Callable {
} catch(CompileError e) {
// Print the error and exit with compile error
System.err.println(e.getMessage());
- System.exit(COMPILE_ERROR);
+ return COMPILE_ERROR;
}
String asmFileName = outputFileNameBase + ".asm";
@@ -463,7 +462,7 @@ public class KickC implements Callable {
}
}
- return null;
+ return CommandLine.ExitCode.OK;
}
private void configVerbosity(Compiler compiler) {
@@ -545,4 +544,32 @@ public class KickC implements Callable {
return i > 0 ? name.substring(i + 1) : "";
}
+ /**
+ * Picocli Parameter Consumer for -D defines that allow both -Dname and -Dname=Value
+ */
+ static class DefineConsumer implements CommandLine.IParameterConsumer {
+ @Override
+ public void consumeParameters(
+ Stack args,
+ CommandLine.Model.ArgSpec argSpec,
+ CommandLine.Model.CommandSpec commandSpec) {
+ if(args.isEmpty()) {
+ throw new CommandLine.ParameterException(commandSpec.commandLine(),
+ "Missing required parameter");
+ }
+ String parameter = args.pop();
+ String[] keyValue = parameter.split("=", 2);
+ String key = keyValue[0];
+ String value = keyValue.length > 1
+ ? keyValue[1]
+ : "1";
+ Map map = argSpec.getValue();
+ if(map==null) {
+ map = new LinkedHashMap<>();
+ argSpec.setValue(map);
+ }
+ map.put(key, value);
+ }
+ }
+
}
diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java
index 3fc082378..136b2cb43 100644
--- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java
+++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java
@@ -23,7 +23,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertTrue;