File tree Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change 6
6
"io/ioutil"
7
7
"os"
8
8
"path/filepath"
9
+ "runtime/debug"
9
10
"strings"
10
11
11
12
"github.com/fatih/color"
@@ -213,13 +214,30 @@ func init() {
213
214
214
215
// Output build info (version, commit, date and builtBy)
215
216
if versionFlag {
216
- fmt .Printf (
217
- "Version:\t %s\n Commit:\t \t %s\n Built\t \t %s by %s\n " ,
218
- version ,
219
- commit ,
220
- date ,
221
- builtBy ,
222
- )
217
+ var buildInfo string
218
+ if date != "unknown" && builtBy != "unknown" {
219
+ buildInfo = fmt .Sprintf ("Built\t \t %s by %s\n " , date , builtBy )
220
+ }
221
+
222
+ if commit != "none" {
223
+ buildInfo = fmt .Sprintf ("Commit:\t \t %s\n %s" , commit , buildInfo )
224
+ }
225
+
226
+ if version == "dev" {
227
+ bi , ok := debug .ReadBuildInfo ()
228
+ if ok {
229
+ version = bi .Main .Version
230
+ if strings .HasPrefix (version , "v" ) {
231
+ version = bi .Main .Version [1 :]
232
+ }
233
+ if len (buildInfo ) == 0 {
234
+ fmt .Printf ("version %s\n " , version )
235
+ os .Exit (0 )
236
+ }
237
+ }
238
+ }
239
+
240
+ fmt .Printf ("Version:\t %s\n %s" , version , buildInfo )
223
241
os .Exit (0 )
224
242
}
225
243
}
You can’t perform that action at this time.
0 commit comments