Skip to content

Commit 79b1381

Browse files
committed
update docs
1 parent 1cd6da4 commit 79b1381

File tree

5 files changed

+75
-25
lines changed

5 files changed

+75
-25
lines changed

cli/main.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ THE SOFTWARE.
2222
package main
2323

2424
import (
25-
goversion "github.com/caarlos0/go-version"
2625
"github.com/foolin/sumdiff/cmd"
26+
"github.com/foolin/sumdiff/vo"
2727
)
2828

2929
var (
30-
version = "dev"
30+
version = "devel"
3131
commit = "none"
3232
date = "unknown"
3333
)
@@ -36,21 +36,17 @@ func main() {
3636
cmd.Execute(buildVersion(version, commit, date))
3737
}
3838

39-
const website = "https://1024km.com/sumdiff"
40-
41-
func buildVersion(version, commit, date string) goversion.Info {
42-
return goversion.GetVersionInfo(
43-
goversion.WithAppDetails("sumdiff", "A useful comparison tool for differences", website),
44-
func(i *goversion.Info) {
45-
if commit != "" {
46-
i.GitCommit = commit
47-
}
48-
if date != "" {
49-
i.BuildDate = date
50-
}
51-
if version != "" {
52-
i.GitVersion = version
53-
}
54-
},
55-
)
39+
func buildVersion(version, commit, date string) vo.AppInfo {
40+
info := vo.NewAppInfo()
41+
if version != "" {
42+
info.Version = version
43+
}
44+
if commit != "" {
45+
info.Commit = commit
46+
}
47+
if date != "" {
48+
info.Date = date
49+
}
50+
51+
return info
5652
}

cmd/root.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ THE SOFTWARE.
2222
package cmd
2323

2424
import (
25-
goversion "github.com/caarlos0/go-version"
25+
"fmt"
26+
"github.com/foolin/sumdiff/vo"
2627
"os"
2728
"path/filepath"
2829

@@ -87,8 +88,9 @@ var rootCmd = &cobra.Command{
8788

8889
// Execute adds all child commands to the root command and sets flags appropriately.
8990
// This is called by main.main(). It only needs to happen once to the rootCmd.
90-
func Execute(verInfo goversion.Info) {
91-
rootCmd.Version = verInfo.String()
91+
func Execute(appInfo vo.AppInfo) {
92+
appInfo.Description = fmt.Sprintf("%v: %v", rootCmd.Use, rootCmd.Long)
93+
rootCmd.Version = appInfo.String()
9294
rootCmd.SetVersionTemplate("{{.Version}}")
9395
err := rootCmd.Execute()
9496
if err != nil {

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/foolin/sumdiff
33
go 1.20
44

55
require (
6-
github.com/caarlos0/go-version v0.1.1
76
github.com/hashicorp/go-multierror v1.1.1
87
github.com/liushuochen/gotable v0.0.0-20221119160816-1113793e7092
98
github.com/mattn/go-runewidth v0.0.15

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/caarlos0/go-version v0.1.1 h1:1bikKHkGGVIIxqCmufhSSs3hpBScgHGacrvsi8FuIfc=
2-
github.com/caarlos0/go-version v0.1.1/go.mod h1:Ze5Qx4TsBBi5FyrSKVg1Ibc44KGV/llAaKGp86oTwZ0=
31
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
42
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
53
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

vo/version.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package vo
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
"strings"
7+
"text/tabwriter"
8+
)
9+
10+
type AppInfo struct {
11+
Description string `json:"description" yaml:"description"`
12+
Version string `json:"version" yaml:"version"`
13+
Commit string `json:"commit" yaml:"commit"`
14+
Date string `json:"date" yaml:"date"`
15+
GoVer string `json:"goVer" yaml:"goVer"`
16+
Compiler string `json:"compiler" yaml:"compiler"`
17+
Platform string `json:"platform" yaml:"platform"`
18+
}
19+
20+
func NewAppInfo() AppInfo {
21+
return AppInfo{
22+
Description: "",
23+
Version: "devel",
24+
Commit: "none",
25+
Date: "none",
26+
GoVer: runtime.Version(),
27+
Compiler: runtime.Compiler,
28+
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
29+
}
30+
}
31+
32+
func (r AppInfo) Array() [][]string {
33+
return [][]string{
34+
{"Version", "Commit", "Date", "GoVer", "Compiler", "Platform"},
35+
{r.Version, r.Commit, r.Date, r.GoVer, r.Compiler, r.Platform},
36+
}
37+
}
38+
39+
func (r AppInfo) String() string {
40+
b := strings.Builder{}
41+
w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0)
42+
if r.Description != "" {
43+
_, _ = fmt.Fprint(w, r.Description)
44+
_, _ = fmt.Fprint(w, "\n\n")
45+
}
46+
_, _ = fmt.Fprintf(w, "Version:\t%s\n", r.Version)
47+
_, _ = fmt.Fprintf(w, "Commit:\t%s\n", r.Commit)
48+
_, _ = fmt.Fprintf(w, "Date:\t%s\n", r.Date)
49+
_, _ = fmt.Fprintf(w, "GoVer:\t%s\n", r.GoVer)
50+
_, _ = fmt.Fprintf(w, "Compiler:\t%s\n", r.Compiler)
51+
_, _ = fmt.Fprintf(w, "Platform:\t%s\n", r.Platform)
52+
53+
_ = w.Flush()
54+
return b.String()
55+
}

0 commit comments

Comments
 (0)