Implement -R command-line option
This has been done at JBCNConf 2019 Hackergarten with the help of
MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/Options.java
asciidoctorj-api/src/main/java/org/asciidoctor/Options.java
@@ -21,6 +21,7 @@ public class Options {
public static final String ERUBY = "eruby";
public static final String COMPACT = "compact";
public static final String DESTINATION_DIR = "destination_dir";
+ public static final String SOURCE_DIR = "source_dir";
public static final String BACKEND = "backend";
public static final String DOCTYPE = "doctype";
public static final String BASEDIR = "base_dir";
@@ -135,6 +136,10 @@ public class Options {
this.options.put(DESTINATION_DIR, destinationDir);
}
+ public void setSourceDir(String srcDir) {
+ this.options.put(SOURCE_DIR, srcDir);
+ }
+
public void setBackend(String backend) {
this.options.put(BACKEND, backend);
}

MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java
asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java
@@ -271,6 +271,20 @@ public class OptionsBuilder {
return this;
}
+ /**
+ * Source directory.
+ *
+ * This must be used alongside {@link #destinationDir(File)}.
+ *
+ * @param srcDir
+ * source directory.
+ * @return this instance.
+ */
+ public OptionsBuilder sourceDir(File srcDir) {
+ this.options.setSourceDir(srcDir.getAbsolutePath());
+ return this;
+ }
+
/**
* Sets a custom or unlisted option.
*

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorCliOptions.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorCliOptions.java
@@ -23,6 +23,7 @@ public class AsciidoctorCliOptions {
public static final String ATTRIBUTE = "-a";
public static final String HELP = "-h";
public static final String DESTINATION_DIR = "-D";
+ public static final String SOURCE_DIR = "-R";
public static final String BASE_DIR = "-B";
public static final String TEMPLATE_DIR = "-T";
public static final String TEMPLATE_ENGINE = "-E";
@@ -88,6 +89,9 @@ public class AsciidoctorCliOptions {
@Parameter(names = { DESTINATION_DIR, "--destination-dir" }, description = "destination output directory (default: directory of source file)")
private String destinationDir;
+ @Parameter(names = { SOURCE_DIR, "--source-dir" }, description = "source directory (requires destination directory)")
+ private String sourceDir;
+
@Parameter(names = { "--trace" }, description = "include backtrace information on errors (default: false)")
private boolean trace = false;
@@ -216,10 +220,18 @@ public class AsciidoctorCliOptions {
return this.destinationDir;
}
+ public String getSourceDir() {
+ return this.sourceDir;
+ }
+
public boolean isDestinationDirOption() {
return this.destinationDir != null;
}
+ public boolean isSourceDirOption() {
+ return this.sourceDir != null;
+ }
+
public boolean isTemplateEngineOption() {
return this.templateEngine != null;
}
@@ -294,6 +306,10 @@ public class AsciidoctorCliOptions {
if (isDestinationDirOption() && !isOutputStdout()) {
optionsBuilder.toDir(new File(this.destinationDir));
+
+ if(isSourceDirOption()) {
+ optionsBuilder.sourceDir(new File(this.sourceDir));
+ }
}
if (isInPlaceRequired()) {

Implement -R command-line option (#818)

This has been done at JBCNConf 2019 Hackergarten with the help of @4lber10.