summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile4
-rw-r--r--pom.xml36
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCli.java62
3 files changed, 102 insertions, 0 deletions
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..66b9e08
--- /dev/null
+++ b/makefile
@@ -0,0 +1,4 @@
+.PHONY: package
+
+package:
+ mvn package -Dmaven.test.skip=true
diff --git a/pom.xml b/pom.xml
index c9af6b7..60dcf8a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,11 @@
<dependencies>
<dependency>
+ <groupId>net.sourceforge.argparse4j</groupId>
+ <artifactId>argparse4j</artifactId>
+ <version>0.9.0</version>
+ </dependency>
+ <dependency>
<groupId>org.zwobble.source-text</groupId>
<artifactId>source-text</artifactId>
<version>0.1.0</version>
@@ -81,6 +86,37 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>3.4.1</version>
+ <configuration>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <manifestEntries>
+ <Main-Class>org.zwobble.hobgoblin.compiler.HobgoblinCli</Main-Class>
+ </manifestEntries>
+ </transformer>
+ </transformers>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.8.0</version>
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCli.java b/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCli.java
new file mode 100644
index 0000000..a4992e4
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCli.java
@@ -0,0 +1,62 @@
+package org.zwobble.hobgoblin.compiler;
+
+import net.sourceforge.argparse4j.ArgumentParsers;
+import net.sourceforge.argparse4j.ext.java7.PathArgumentType;
+import net.sourceforge.argparse4j.inf.ArgumentParserException;
+import net.sourceforge.argparse4j.inf.Namespace;
+import org.zwobble.hobgoblin.compiler.errors.SourceError;
+import org.zwobble.hobgoblin.compiler.sources.NullSource;
+
+import java.io.IOException;
+import java.nio.file.Path;
+
+public class HobgoblinCli {
+ public static void main(String[] rawArgs) throws IOException, InterruptedException {
+ var args = parseArgs(rawArgs);
+ try {
+ compile(args);
+ } catch (SourceError error) {
+ if (!(error.source() instanceof NullSource)) {
+ System.err.println(error.source().describe());
+ }
+ System.err.println(error.getMessage());
+ System.exit(2);
+ }
+ }
+
+ private static void compile(Namespace args) throws IOException, InterruptedException {
+ var sourcePath = args.<Path>get("source");
+
+ switch (args.<Command>get("command")) {
+ case COMPILE -> {
+ HobgoblinCompiler.compile(sourcePath);
+ }
+ }
+ }
+
+ private static Namespace parseArgs(String[] args) {
+ var parser = ArgumentParsers.newFor("hobgoblin").build()
+ .defaultHelp(true);
+
+ var subparsers = parser.addSubparsers();
+
+ var compileSubParser = subparsers.addParser("compile");
+ compileSubParser.setDefault("command", Command.COMPILE);
+ compileSubParser
+ .addArgument("source")
+ .type(new PathArgumentType())
+ .required(true);
+
+ try {
+ return parser.parseArgs(args);
+ } catch (ArgumentParserException e) {
+ parser.handleError(e);
+ System.exit(1);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private enum Command {
+ COMPILE,
+ }
+}