Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Commit

Permalink
main.go: add checkmark to Go version
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCarrion committed Feb 7, 2020
1 parent 4cd0a6f commit c1c1724
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The following output will be generated:
```
| | github.com/MarioCarrion/nit | github.com/MarioCarrion/versions |
|--- | :---: | :---: |
| Go version | 1.13 | 1.13 |
| :white_check_mark: Go version| 1.13| 1.13
| github.com/golangci/golangci-lint | v1.23.3 | v1.23.2 |
| :white_check_mark: github.com/google/go-cmp | v0.2.0 | |
| :white_check_mark: github.com/pkg/errors | v0.8.1 | |
Expand All @@ -53,7 +53,7 @@ Which renders like this in Markdown

| | github.com/MarioCarrion/nit | github.com/MarioCarrion/versions |
|--- | :---: | :---: |
| Go version | 1.13 | 1.13 |
| :white_check_mark: Go version| 1.13| 1.13
| github.com/golangci/golangci-lint | v1.23.3 | v1.23.2 |
| :white_check_mark: github.com/google/go-cmp | v0.2.0 | |
| :white_check_mark: github.com/pkg/errors | v0.8.1 | |
Expand Down
41 changes: 29 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,26 @@ func parse(files []string) ([]*modfile.File, error) {
func printMarkdown(table Table) {
line0 := "|"
line1 := "|---"
line2 := "| Go version "
line2 := "Go version"

var lastversion string
same := true

for i, name := range table.Modules {
line0 = fmt.Sprintf("%s | %s ", line0, name)
line1 = fmt.Sprintf("%s | :---: ", line1)
line2 = fmt.Sprintf("%s | %s ", line2, table.Versions[i])
line2 = fmt.Sprintf("%s| %s", line2, table.Versions[i])

same, lastversion = sameVersion(same, lastversion, table.Versions[i])
}

fmt.Printf("%s |\n", line0)
fmt.Printf("%s |\n", line1)
fmt.Printf("%s |\n", line2)

if same {
line2 = fmt.Sprintf(":white_check_mark: %s", line2)
}
fmt.Printf("| %s \n", line2)

sortedpkgs := make([]string, len(table.Packages))

Expand All @@ -149,9 +158,10 @@ func printMarkdown(table Table) {
for _, pkg := range sortedpkgs {
v := table.Packages[pkg]

var line, lastversion string
var line string

same := true
same = true
lastversion = ""

for _, p := range v {
var version string
Expand All @@ -161,13 +171,7 @@ func printMarkdown(table Table) {
version = p.Version
}

if lastversion == "" {
lastversion = version
}

if same && lastversion != version && version != "" {
same = false
}
same, lastversion = sameVersion(same, lastversion, version)

line = fmt.Sprintf("%s %s ", line, version)
if p.IsIndirect {
Expand All @@ -182,6 +186,7 @@ func printMarkdown(table Table) {
}

var prefix string

if same {
prefix = fmt.Sprintf(":white_check_mark: %s", pkg)
} else {
Expand All @@ -193,3 +198,15 @@ func printMarkdown(table Table) {
fmt.Println(line)
}
}

func sameVersion(same bool, lastversion, newversion string) (bool, string) {
if lastversion == "" {
lastversion = newversion
}

if same && lastversion != newversion && newversion != "" {
same = false
}

return same, lastversion
}

0 comments on commit c1c1724

Please # to comment.