diff --git a/src/main/java/eu/m724/blog/Main.java b/src/main/java/eu/m724/blog/Main.java index 09b5884..835eb5b 100644 --- a/src/main/java/eu/m724/blog/Main.java +++ b/src/main/java/eu/m724/blog/Main.java @@ -5,6 +5,7 @@ import eu.m724.blog.data.Post; import eu.m724.blog.data.Site; import in.wilsonl.minifyhtml.Configuration; import in.wilsonl.minifyhtml.MinifyHtml; +import org.apache.commons.cli.*; import org.apache.commons.io.file.PathUtils; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.RepositoryBuilder; @@ -27,18 +28,37 @@ public class Main { public static void main(String[] args) throws IOException { System.out.println("Hello world!"); - var start = System.nanoTime(); + var options = new Options() + .addOption("f", "force", false, "Overwrite current build. Default: no") + .addOption("dir", "working-dir", true, "Working directory. Default: current directory") + .addOption("t", "template-dir", true, "Template directory. Default: working directory/template") + .addOption("o", "output-dir", true, "Output directory. Default: working directory/generated_out") + .addOption("s", "server", false, "Run webserver. Default: no"); - var workingDirectory = Path.of("m724"); - var templateDirectory = workingDirectory.resolve("template"); - var outputDirectory = workingDirectory.resolve("generated_out"); - var force = true; + CommandLine commandLine; + try { + commandLine = new DefaultParser().parse(options, args); + } catch (ParseException e) { + System.out.println(e.getMessage()); + new HelpFormatter().printHelp("utility-name", options); - var server = true; + System.exit(1); + return; + } + + + var workingDirectory = Path.of(commandLine.getOptionValue("working-dir", ".")); + var templateDirectory = Path.of(commandLine.getOptionValue("output-dir", workingDirectory.resolve("template").toString())); + var outputDirectory = Path.of(commandLine.getOptionValue("output-dir", workingDirectory.resolve("generated_out").toString())); + var force = commandLine.hasOption("force"); + + var server = commandLine.hasOption("server"); var openBrowser = true; // + var start = System.nanoTime(); + var repository = new RepositoryBuilder() .setGitDir(workingDirectory.resolve(".git").toFile()) .build(); diff --git a/src/main/java/eu/m724/blog/data/Site.java b/src/main/java/eu/m724/blog/data/Site.java index 68721a6..64292ce 100644 --- a/src/main/java/eu/m724/blog/data/Site.java +++ b/src/main/java/eu/m724/blog/data/Site.java @@ -15,7 +15,7 @@ public record Site( Map custom ) { public static Site fromConfig(Git git) throws IOException { - var content = Files.readString(git.getRepository().getDirectory().toPath().getParent().resolve("config.json")); + var content = Files.readString(git.getRepository().getDirectory().toPath().getParent().resolve("site-config.json")); var json = new JSONObject(content); String name = null;