33
33
import org .asciidoctor .ast .Document ;
34
34
import org .asciidoctor .jruby .AsciiDocDirectoryWalker ;
35
35
import picocli .CommandLine ;
36
+ import picocli .CommandLine .ArgGroup ;
36
37
import picocli .CommandLine .Command ;
37
38
import picocli .CommandLine .Option ;
38
39
39
- @ Command (name = "extract" , mixinStandardHelpOptions = true , version = "1.0" ,
40
- description = "Create a modular documentation layout from a directory of asciidoc files." )
40
+ @ Command (name = "extract" , mixinStandardHelpOptions = true , version = "1.0" , description = "Create a modular documentation layout from a directory of asciidoc files." )
41
41
public class ExtractionRunner implements Callable <Integer > {
42
42
private List <Assembly > assemblies ;
43
43
private Set <ExtractedModule > modules ;
44
44
private List <Issue > issues = new ArrayList <>();
45
+ @ ArgGroup (heading = "Input" , exclusive = true , multiplicity = "1" )
46
+ InputOptions inputOptions ;
47
+ @ ArgGroup (heading = "Output" , exclusive = true , multiplicity = "1" )
48
+ OutputOptions outputOptions ;
45
49
46
- @ Option (names = {"-s" , "--sourceDir" }, description = "Directory containing the input asciidoc files." )
47
- File inputDir ;
50
+ static class InputOptions {
51
+ @ Option (names = { "-s" , "--sourceDir" }, description = "Directory containing the input asciidoc files." )
52
+ File inputDir ;
48
53
49
- @ Option (names = {"-o" , "--outputDir" }, description = "Directory to place generated modules and assemblies." )
50
- File outputDir ;
54
+ @ ArgGroup (exclusive = false )
55
+ GitInputOptions gitInputOptions ;
56
+ }
57
+
58
+ static class OutputOptions {
59
+ @ Option (names = { "-o" , "--outputDir" }, description = "Directory to place generated modules and assemblies." )
60
+ File outputDir ;
61
+
62
+ @ ArgGroup (exclusive = false )
63
+ GitOutputOptions gitOutputOptions ;
64
+ }
51
65
52
- @ Option (names = {"-sr" , "--sourceRepo" }, description = "Git URL to the source repository." )
53
- String sourceRepo ;
66
+ static class GitInputOptions {
67
+ @ Option (names = { "-sr" , "--sourceRepo" }, description = "Git URL to the source repository." , required = true )
68
+ String sourceRepo ;
54
69
55
- @ Option (names = {"-sb" , "--sourceBranch" }, defaultValue = "master" , description = "Branch in source repository." )
56
- String sourceBranch ;
70
+ @ Option (names = { "-sb" ,
71
+ "--sourceBranch" }, defaultValue = "master" , description = "Branch in source repository." )
72
+ String sourceBranch ;
73
+ }
57
74
58
- @ Option (names = {"-or" , "--outputRepo" }, description = "Git URL to the output repository." )
59
- String outputRepo ;
75
+ static class GitOutputOptions {
76
+ @ Option (names = { "-or" , "--outputRepo" }, description = "Git URL to the output repository." , required = true )
77
+ String outputRepo ;
60
78
61
- @ Option (names = {"-ob" , "--outputBranch" }, defaultValue = "master" , description = "Branch in output repository." )
62
- String outputBranch ;
79
+ @ Option (names = { "-ob" ,
80
+ "--outputBranch" }, defaultValue = "master" , description = "Branch in output repository." )
81
+ String outputBranch ;
82
+ }
63
83
64
84
public ExtractionRunner () {
65
85
this .assemblies = new ArrayList <>();
@@ -73,7 +93,7 @@ public static void main(String... args) {
73
93
74
94
@ Override
75
95
public Integer call () {
76
- var config = new Configuration (this .inputDir , this .outputDir );
96
+ var config = new Configuration (this .inputOptions . inputDir , this . outputOptions .outputDir );
77
97
var preprocessor = new ReaderPreprocessor ();
78
98
79
99
OptionsBuilder optionsBuilder = OptionsBuilder .options ();
@@ -104,7 +124,8 @@ public Integer call() {
104
124
}
105
125
106
126
/**
107
- * returns true if all went well. false if there was some problem with uniqueness.
127
+ * returns true if all went well. false if there was some problem with
128
+ * uniqueness.
108
129
*/
109
130
private void findSections (Document doc , List <String > lines ) {
110
131
// TODO: This should probably be configurable
@@ -133,14 +154,11 @@ private void writeAssemblies(Configuration config) {
133
154
this .assemblies .forEach (a -> {
134
155
try {
135
156
// Create any directories that need to be created
136
- Path assembliesDir = Files .createDirectories (config .getOutputDirectory ().toPath ().resolve ("assemblies" ));
157
+ Path assembliesDir = Files
158
+ .createDirectories (config .getOutputDirectory ().toPath ().resolve ("assemblies" ));
137
159
var outputFile = Paths .get (assembliesDir .toString (), a .getFilename ());
138
160
try (Writer output = new FileWriter (outputFile .toFile ())) {
139
- output .append (templateStart )
140
- .append ("\n " )
141
- .append (a .getSource ())
142
- .append ("\n " )
143
- .append (templateEnd );
161
+ output .append (templateStart ).append ("\n " ).append (a .getSource ()).append ("\n " ).append (templateEnd );
144
162
}
145
163
} catch (IOException e ) {
146
164
// TODO: We blew-up in an unexpected way, handle this
@@ -193,10 +211,11 @@ private void moveNonadoc(Configuration config) {
193
211
var destinationDir = assetsDir .toFile ().toPath ();
194
212
var adocExtRegex = Pattern .compile ("^[^_.].*\\ .a((sc(iidoc)?)|d(oc)?)$" );
195
213
196
- Files .walkFileTree (sourceDir , EnumSet .of (FileVisitOption .FOLLOW_LINKS ),
197
- Integer . MAX_VALUE , new SimpleFileVisitor <>() {
214
+ Files .walkFileTree (sourceDir , EnumSet .of (FileVisitOption .FOLLOW_LINKS ), Integer . MAX_VALUE ,
215
+ new SimpleFileVisitor <>() {
198
216
@ Override
199
- public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
217
+ public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs )
218
+ throws IOException {
200
219
var targetDir = destinationDir .resolve (sourceDir .relativize (dir ));
201
220
202
221
// Create the directory structure in the new location
0 commit comments