This commit is contained in:
parent
9b681dbec1
commit
cbb7dab7f3
2 changed files with 19 additions and 5 deletions
1
pom.xml
1
pom.xml
|
@ -58,6 +58,7 @@
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
|
|
@ -23,29 +23,37 @@ public class Main {
|
||||||
var options = new Options()
|
var options = new Options()
|
||||||
.addOption("h", "help", false, "Show help")
|
.addOption("h", "help", false, "Show help")
|
||||||
.addOption("f", "force", false, "Overwrite current build")
|
.addOption("f", "force", false, "Overwrite current build")
|
||||||
.addOption("dir", "working-dir", true, "Working directory. Default: current directory")
|
|
||||||
.addOption("t", "template-dir", true, "Template directory. Default: working directory/template")
|
.addOption("t", "template-dir", true, "Template directory. Default: working directory/template")
|
||||||
.addOption("o", "output-dir", true, "Output directory. Default: working directory/generated_out")
|
.addOption("o", "output-dir", true, "Output directory. Default: working directory/generated_out")
|
||||||
.addOption("s", "server", false, "Run webserver. Default: no");
|
.addOption("s", "server", false, "Run webserver. Default: no")
|
||||||
|
.addOption("d", "draft", false, "Render drafts. Default: only with server");
|
||||||
|
|
||||||
CommandLine commandLine;
|
CommandLine commandLine;
|
||||||
|
String wdStr;
|
||||||
try {
|
try {
|
||||||
commandLine = new DefaultParser().parse(options, args);
|
commandLine = new DefaultParser().parse(options, args);
|
||||||
|
|
||||||
if (commandLine.hasOption("help"))
|
if (commandLine.hasOption("help"))
|
||||||
throw new ParseException("Showing help");
|
throw new ParseException("Showing help");
|
||||||
|
|
||||||
|
if (commandLine.getArgs().length == 0)
|
||||||
|
throw new ParseException("Missing required argument: WORKDIR");
|
||||||
|
|
||||||
|
wdStr = commandLine.getArgs()[0];
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
new HelpFormatter().printHelp("blog-software-java", options);
|
new HelpFormatter().printHelp("blog-software-java [OPTION]... [WORKDIR]", options);
|
||||||
|
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var workingDirectory = Path.of(commandLine.getOptionValue("working-dir", "."));
|
var workingDirectory = Path.of(wdStr);
|
||||||
var templateDirectory = Path.of(commandLine.getOptionValue("output-dir", workingDirectory.resolve("template").toString()));
|
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 outputDirectory = Path.of(commandLine.getOptionValue("output-dir", workingDirectory.resolve("generated_out").toString()));
|
||||||
var force = commandLine.hasOption("force");
|
var force = commandLine.hasOption("force");
|
||||||
|
var renderDrafts = commandLine.hasOption("draft");
|
||||||
|
|
||||||
var server = commandLine.hasOption("server");
|
var server = commandLine.hasOption("server");
|
||||||
var openBrowser = true;
|
var openBrowser = true;
|
||||||
|
@ -65,7 +73,7 @@ public class Main {
|
||||||
if (force) {
|
if (force) {
|
||||||
PathUtils.deleteDirectory(outputDirectory);
|
PathUtils.deleteDirectory(outputDirectory);
|
||||||
} else {
|
} else {
|
||||||
throw new FileAlreadyExistsException(outputDirectory.toString(), null, "Output directory already exists");
|
throw new FileAlreadyExistsException(outputDirectory.toString(), null, "Output directory already exists. --force?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +102,11 @@ public class Main {
|
||||||
path = postDirectory.relativize(path);
|
path = postDirectory.relativize(path);
|
||||||
var post = Post.fromFile(git, path);
|
var post = Post.fromFile(git, path);
|
||||||
|
|
||||||
|
if (post.draft() && !renderDrafts) {
|
||||||
|
System.out.println("Post " + path.getFileName() + ": draft, ignoring");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var render = template.renderPost(site, post);
|
var render = template.renderPost(site, post);
|
||||||
var outFile = outputDirectory.resolve("post").resolve(path);
|
var outFile = outputDirectory.resolve("post").resolve(path);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue