diff --git a/pom.xml b/pom.xml index 107476e..f0773ea 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.nqm gis - 1.0.0-beta + 1.0.0 ${packaging} diff --git a/src/main/java/org/nqm/Gis.java b/src/main/java/org/nqm/Gis.java index d3db8a9..3b20e8a 100644 --- a/src/main/java/org/nqm/Gis.java +++ b/src/main/java/org/nqm/Gis.java @@ -11,7 +11,7 @@ name = "gis", description = "Git extension wrapper which supports submodules", mixinStandardHelpOptions = true, - version = "1.0.0-beta") + version = "1.0.0") public class Gis extends GitCommand { @Option(names = "-v", description = "Show more details information.", scope = ScopeType.INHERIT) diff --git a/src/main/java/org/nqm/utils/StdOutUtils.java b/src/main/java/org/nqm/utils/StdOutUtils.java index d53a9dc..3d5153c 100644 --- a/src/main/java/org/nqm/utils/StdOutUtils.java +++ b/src/main/java/org/nqm/utils/StdOutUtils.java @@ -2,6 +2,11 @@ import static java.lang.System.err; // NOSONAR import static java.lang.System.out; // NOSONAR +import static java.util.function.Predicate.not; +import java.util.Optional; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class StdOutUtils { @@ -40,4 +45,60 @@ public static String coloringWord(String word, String color) { public static String coloringWord(Character c, String color) { return color + c + CL_RESET; } + + public static String buildStaging(char[] chars) { + return Optional.of(chars[0]) + .map(s -> s != '.' ? coloringWord(s, CL_GREEN) : s + "") + .orElse("") + + Optional.of(chars[1]) + .map(s -> s != '.' ? coloringWord(s, CL_RED) : s + "") + .orElse("") + + " "; + } + + private static String buildAheadBehind(String[] splitS) { + var ahead = Optional.of(splitS[2]) + .map(s -> s.replace("+", "")) + .filter(not("0"::equals)) + .map(s -> "ahead " + coloringWord(s, CL_GREEN)) + .orElse(""); + var behind = Optional.of(splitS[3]) + .map(s -> s.replace("-", "")) + .filter(not("0"::equals)) + .map(s -> "behind " + coloringWord(s, CL_RED)) + .orElse(""); + return Stream.of(ahead, behind).filter(not(String::isBlank)).collect(Collectors.joining(", ")); + } + + public static String gitStatus(String line) { + var sb = new StringBuilder(); + if (line.startsWith("# branch.oid")) { + return ""; + } + if (line.startsWith("# branch.head")) { + sb.append("\n ## ").append(coloringWord(line.split("\s")[2], CL_GREEN)); + } + else if (line.startsWith("# branch.upstream")) { + sb.append("...").append(coloringWord(line.split("\s")[2], CL_RED)); + } + else if (line.startsWith("# branch.ab")) { + Optional.of(line.split("\s")) + .map(StdOutUtils::buildAheadBehind) + .filter(GisStringUtils::isNotBlank) + .map(" [%s]"::formatted) + .ifPresent(sb::append); + } + else { + final var immutableLine = line; + UnaryOperator getFiles = filesChange -> immutableLine.startsWith("2") + ? Optional.of(filesChange.split("\t")).map(s -> s[1] + " -> " + s[0]).orElse("") + : filesChange; + + Optional.of(line.split("\s")) + .ifPresent(splitS -> sb.append("\n ") + .append(Optional.of(splitS[1].toCharArray()).map(StdOutUtils::buildStaging).orElse("")) + .append(Optional.of(splitS[splitS.length - 1]).map(getFiles).orElse(""))); + } + return sb.toString(); + } } diff --git a/src/main/java/org/nqm/vertx/CommandVerticle.java b/src/main/java/org/nqm/vertx/CommandVerticle.java index f526d1e..ffc554f 100644 --- a/src/main/java/org/nqm/vertx/CommandVerticle.java +++ b/src/main/java/org/nqm/vertx/CommandVerticle.java @@ -1,12 +1,9 @@ package org.nqm.vertx; import static java.lang.System.out; // NOSONAR -import static java.util.function.Predicate.not; import static org.nqm.utils.GisStringUtils.isNotBlank; -import static org.nqm.utils.StdOutUtils.CL_GREEN; -import static org.nqm.utils.StdOutUtils.CL_RED; -import static org.nqm.utils.StdOutUtils.coloringWord; import static org.nqm.utils.StdOutUtils.errln; +import static org.nqm.utils.StdOutUtils.gitStatus; import static org.nqm.utils.StdOutUtils.infof; import static org.nqm.utils.StdOutUtils.warnln; import java.io.BufferedReader; @@ -14,12 +11,8 @@ import java.io.InputStreamReader; import java.nio.file.Path; import java.util.Optional; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.nqm.config.GisConfig; import org.nqm.config.GisLog; -import org.nqm.utils.GisStringUtils; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; @@ -93,60 +86,4 @@ private void safelyPrint(Process pr) { Thread.currentThread().interrupt(); } } - - private static String gitStatus(String line) { - var sb = new StringBuilder(); - if (line.startsWith("# branch.oid")) { - return ""; - } - if (line.startsWith("# branch.head")) { - sb.append("\n ## ").append(coloringWord(line.split("\s")[2], CL_GREEN)); - } - else if (line.startsWith("# branch.upstream")) { - sb.append("...").append(coloringWord(line.split("\s")[2], CL_RED)); - } - else if (line.startsWith("# branch.ab")) { - Optional.of(line.split("\s")) - .map(CommandVerticle::buildAheadBehind) - .filter(GisStringUtils::isNotBlank) - .map(" [%s]"::formatted) - .ifPresent(sb::append); - } - else { - final var immutableLine = line; - UnaryOperator getFiles = filesChange -> immutableLine.startsWith("2") - ? Optional.of(filesChange.split("\t")).map(s -> s[1] + " -> " + s[0]).orElse("") - : filesChange; - - Optional.of(line.split("\s")) - .ifPresent(splitS -> sb.append("\n ") - .append(Optional.of(splitS[1].toCharArray()).map(CommandVerticle::buildStaging).orElse("")) - .append(Optional.of(splitS[splitS.length - 1]).map(getFiles).orElse(""))); - } - return sb.toString(); - } - - private static String buildAheadBehind(String[] splitS) { - var ahead = Optional.of(splitS[2]) - .map(s -> s.replace("+", "")) - .filter(not("0"::equals)) - .map(s -> "ahead " + coloringWord(s, CL_GREEN)) - .orElse(""); - var behind = Optional.of(splitS[3]) - .map(s -> s.replace("-", "")) - .filter(not("0"::equals)) - .map(s -> "behind " + coloringWord(s, CL_RED)) - .orElse(""); - return Stream.of(ahead, behind).filter(not(String::isBlank)).collect(Collectors.joining(", ")); - } - - private static String buildStaging(char[] chars) { - return Optional.of(chars[0]) - .map(s -> s != '.' ? coloringWord(s, CL_GREEN) : s + "") - .orElse("") + - Optional.of(chars[1]) - .map(s -> s != '.' ? coloringWord(s, CL_RED) : s + "") - .orElse("") - + " "; - } }