Skip to content

Commit f022d70

Browse files
committed
improve version
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 18dd56a commit f022d70

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

version/version.go

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,63 @@ type (
2222

2323
const DefaultTitle = `{{.App}} v{{.Version}} ({{.GitCommit}}); {{.Go}}/{{.Arch}}; by {{.Author}}; built at {{.BuildDate}})`
2424

25-
func New() *Version {
25+
func New(opts ...VersionOptionFunc) *Version {
2626
ver := Version{
2727
Go: runtime.Version(),
2828
Arch: runtime.GOARCH,
2929
}
3030

31+
for _, opt := range opts {
32+
opt(&ver)
33+
}
34+
3135
return &ver
3236
}
3337

38+
type VersionOptionFunc func(*Version)
39+
40+
// WithApp sets the app
41+
func WithApp(val string) VersionOptionFunc {
42+
return func(ver *Version) {
43+
ver.App = val
44+
}
45+
}
46+
47+
// WithVersion sets the version
48+
func WithVersion(val string) VersionOptionFunc {
49+
return func(ver *Version) {
50+
ver.Version = val
51+
}
52+
}
53+
54+
// WithGitCommit sets the git commit
55+
func WithGitCommit(val string) VersionOptionFunc {
56+
return func(ver *Version) {
57+
ver.GitCommit = val
58+
}
59+
}
60+
61+
// WithGitTag sets the git tag
62+
func WithGitTag(val string) VersionOptionFunc {
63+
return func(ver *Version) {
64+
ver.GitTag = val
65+
}
66+
}
67+
68+
// WithBuildDate sets the build tage
69+
func WithBuildDate(val string) VersionOptionFunc {
70+
return func(ver *Version) {
71+
ver.BuildDate = val
72+
}
73+
}
74+
75+
// WithAuthor sets the author
76+
func WithAuthor(val string) VersionOptionFunc {
77+
return func(ver *Version) {
78+
ver.Author = val
79+
}
80+
}
81+
3482
func (v *Version) SetApp(val string) *Version {
3583
v.App = val
3684
return v
@@ -56,6 +104,11 @@ func (v *Version) SetBuildDate(val string) *Version {
56104
return v
57105
}
58106

107+
func (v *Version) SetAuthor(val string) *Version {
108+
v.Author = val
109+
return v
110+
}
111+
59112
func (v *Version) Title(tmpl *string) string {
60113
var buf bytes.Buffer
61114

0 commit comments

Comments
 (0)