Skip to content

Commit

Permalink
release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nqminhuit committed Apr 10, 2022
1 parent 2937388 commit 3c8d8f8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 66 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nqm</groupId>
<artifactId>gis</artifactId>
<version>1.0.0-beta</version>
<version>1.0.0</version>
<packaging>${packaging}</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nqm/Gis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/nqm/utils/StdOutUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String> 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();
}
}
65 changes: 1 addition & 64 deletions src/main/java/org/nqm/vertx/CommandVerticle.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
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;
import java.io.IOException;
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;

Expand Down Expand Up @@ -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<String> 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("")
+ " ";
}
}

0 comments on commit 3c8d8f8

Please sign in to comment.