Skip to content

Commit c4749b3

Browse files
adding updated readme
Signed-off-by: Christopher Hein <[email protected]>
1 parent be514ca commit c4749b3

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

readme.adoc

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ simple way. Supporting multiple flags for mutating the output.
77
== Usage
88

99
To use this package you will need to create `cobra` command for version such as
10-
this:
10+
this.
1111

1212
[source,go]
1313
----
@@ -28,18 +28,7 @@ var (
2828
Use: "version",
2929
Short: "Version will output the current build information",
3030
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),
4332
}
4433
)
4534
@@ -49,22 +38,40 @@ func init() {
4938
}
5039
----
5140

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+
----
5360

5461
[source,shell]
5562
----
5663
go build -ldflags "-X main.commit=<SOMEHASH> -X main.date=<SOMEDATE>"
5764
----
5865

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:
6067

6168
[source,shell]
6269
----
6370
$ ./my-cli version
6471
{"Version":"dev","Commit":"<SOMEHASH>","Date":"<SOMEDATE>"}
6572
----
6673

67-
Or to make this human readible you could use:
74+
Or to make this human readable you could use:
6875

6976
[source,shell]
7077
----

0 commit comments

Comments
 (0)