44import static org .nqm .utils .GisStringUtils .isNotBlank ;
55import static org .nqm .utils .StdOutUtils .errln ;
66import static org .nqm .utils .StdOutUtils .gitStatus ;
7+ import static org .nqm .utils .StdOutUtils .gitStatusOneLine ;
78import static org .nqm .utils .StdOutUtils .infof ;
89import static org .nqm .utils .StdOutUtils .warnln ;
910import java .io .BufferedReader ;
1011import java .io .IOException ;
1112import java .io .InputStreamReader ;
1213import java .nio .file .Path ;
14+ import java .util .Objects ;
1315import java .util .Optional ;
16+ import java .util .stream .Stream ;
1417import org .nqm .config .GisConfig ;
1518import org .nqm .config .GisLog ;
1619import io .vertx .core .AbstractVerticle ;
1922public class CommandVerticle extends AbstractVerticle {
2023
2124 private final String [] commandWithArgs ;
25+ private String gisOption ;
2226 private final Path path ;
2327
2428 public CommandVerticle (Path path , String ... args ) {
2529 this .path = path ;
26- this .commandWithArgs = new String [args .length + 1 ];
27- this .commandWithArgs [0 ] = GisConfig .GIT_HOME_DIR ;
28- for (int i = 0 ; i < args .length ; i ++) {
29- this .commandWithArgs [i + 1 ] = args [i ];
30- }
30+ this .commandWithArgs = buildCommandWithArgs (args );
3131 GisLog .debug ("executing command '%s' under module '%s'" , commandWithArgs , path .getFileName ());
3232 GisVertx .eventAddDir (path );
3333 }
@@ -38,6 +38,24 @@ public CommandVerticle() {
3838 GisVertx .eventAddDir (Path .of ("." ));
3939 }
4040
41+ private String [] buildCommandWithArgs (String ... args ) {
42+ var cmdWithArgs = new String [args .length + 1 ];
43+ cmdWithArgs [0 ] = GisConfig .GIT_HOME_DIR ;
44+ var n = args .length ;
45+ for (int i = 0 ; i < n - 1 ; i ++) {
46+ cmdWithArgs [i + 1 ] = args [i ];
47+ }
48+ // for better performance it is to required all '--gis' options to be at the end of cmd
49+ var lastArg = args [n - 1 ];
50+ if (args [n - 1 ].startsWith ("--gis" )) {
51+ this .gisOption = lastArg ;
52+ }
53+ else {
54+ cmdWithArgs [n ] = lastArg ;
55+ }
56+ return Stream .of (cmdWithArgs ).filter (Objects ::nonNull ).toArray (String []::new );
57+ }
58+
4159 @ Override
4260 public void start () {
4361 if (path == null ) {
@@ -67,7 +85,9 @@ private void safelyPrint(Process pr) {
6785 var sb = new StringBuilder (infof ("%s" , "" + path .getFileName ()));
6886 try {
6987 while (isNotBlank (line = input .readLine ())) {
70- sb .append (commandWithArgs [1 ].equals ("status" ) ? gitStatus (line ) : "%n %s" .formatted (line ));
88+ sb .append (commandWithArgs [1 ].equals ("status" )
89+ ? "--gis-one-line" .equals (gisOption ) ? gitStatusOneLine (line ) : gitStatus (line )
90+ : "%n %s" .formatted (line ));
7191 }
7292 out .println (sb .toString ());
7393 Optional .of (pr .waitFor ())
0 commit comments