3333import org .asciidoctor .ast .Document ;
3434import org .asciidoctor .jruby .AsciiDocDirectoryWalker ;
3535import picocli .CommandLine ;
36+ import picocli .CommandLine .ArgGroup ;
3637import picocli .CommandLine .Command ;
3738import picocli .CommandLine .Option ;
3839
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." )
4141public class ExtractionRunner implements Callable <Integer > {
4242 private List <Assembly > assemblies ;
4343 private Set <ExtractedModule > modules ;
4444 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 ;
4549
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 ;
4853
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+ }
5165
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 ;
5469
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+ }
5774
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 ;
6078
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+ }
6383
6484 public ExtractionRunner () {
6585 this .assemblies = new ArrayList <>();
@@ -73,7 +93,7 @@ public static void main(String... args) {
7393
7494 @ Override
7595 public Integer call () {
76- var config = new Configuration (this .inputDir , this .outputDir );
96+ var config = new Configuration (this .inputOptions . inputDir , this . outputOptions .outputDir );
7797 var preprocessor = new ReaderPreprocessor ();
7898
7999 OptionsBuilder optionsBuilder = OptionsBuilder .options ();
@@ -104,7 +124,8 @@ public Integer call() {
104124 }
105125
106126 /**
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.
108129 */
109130 private void findSections (Document doc , List <String > lines ) {
110131 // TODO: This should probably be configurable
@@ -133,14 +154,11 @@ private void writeAssemblies(Configuration config) {
133154 this .assemblies .forEach (a -> {
134155 try {
135156 // 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" ));
137159 var outputFile = Paths .get (assembliesDir .toString (), a .getFilename ());
138160 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 );
144162 }
145163 } catch (IOException e ) {
146164 // TODO: We blew-up in an unexpected way, handle this
@@ -193,10 +211,11 @@ private void moveNonadoc(Configuration config) {
193211 var destinationDir = assetsDir .toFile ().toPath ();
194212 var adocExtRegex = Pattern .compile ("^[^_.].*\\ .a((sc(iidoc)?)|d(oc)?)$" );
195213
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 <>() {
198216 @ Override
199- public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
217+ public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs )
218+ throws IOException {
200219 var targetDir = destinationDir .resolve (sourceDir .relativize (dir ));
201220
202221 // Create the directory structure in the new location
0 commit comments