@@ -7,7 +7,7 @@ simple way. Supporting multiple flags for mutating the output.
7
7
== Usage
8
8
9
9
To use this package you will need to create `cobra` command for version such as
10
- this:
10
+ this.
11
11
12
12
[source,go]
13
13
----
28
28
Use: "version",
29
29
Short: "Version will output the current build information",
30
30
Long: ``,
31
- Run: func(_ *cobra.Command, _ []string) {
32
- var response string
33
- versionOutput := goversion.New(version, commit, date)
34
-
35
- if shortened {
36
- response = versionOutput.ToShortened()
37
- } else {
38
- response = versionOutput.ToJSON()
39
- }
40
- fmt.Printf("%+v", response)
41
- return
42
- },
31
+ Run: goVersion.Func(shortened, version, commit, date),
43
32
}
44
33
)
45
34
@@ -49,22 +38,40 @@ func init() {
49
38
}
50
39
----
51
40
52
- When you do this then you can pass in these flags at build time.
41
+ When you do this then you can pass in these flags at build time. _If you'd like
42
+ more control of the output you can change the `Run` function to something more
43
+ like this.
44
+
45
+ [source,go]
46
+ ----
47
+ Run: func(_ *cobra.Command, _ []string) {
48
+ var response string
49
+ versionOutput := New(version, commit, date)
50
+
51
+ if shortened {
52
+ response = versionOutput.ToShortened()
53
+ } else {
54
+ response = versionOutput.ToJSON()
55
+ }
56
+ fmt.Printf("%+v", response)
57
+ return
58
+ },
59
+ ----
53
60
54
61
[source,shell]
55
62
----
56
63
go build -ldflags "-X main.commit=<SOMEHASH> -X main.date=<SOMEDATE>"
57
64
----
58
65
59
- This then gives your CLI thw ability to use this for the JSON output:
66
+ This then gives your CLI the ability to use this for the JSON output:
60
67
61
68
[source,shell]
62
69
----
63
70
$ ./my-cli version
64
71
{"Version":"dev","Commit":"<SOMEHASH>","Date":"<SOMEDATE>"}
65
72
----
66
73
67
- Or to make this human readible you could use:
74
+ Or to make this human readable you could use:
68
75
69
76
[source,shell]
70
77
----
0 commit comments