File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ var rootCmd = &cobra.Command{
11
11
func init () {
12
12
rootCmd .AddCommand (mountCmd )
13
13
rootCmd .AddCommand (umountCmd )
14
+ rootCmd .AddCommand (versionCmd )
14
15
}
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "github.com/spf13/cobra"
6
+ "runtime/debug"
7
+ "time"
8
+ )
9
+
10
+ var versionCmd = & cobra.Command {
11
+ Use : "version" ,
12
+ Short : "Print version information" ,
13
+ Run : func (cmd * cobra.Command , args []string ) {
14
+ fmt .Println (getVersionString ())
15
+ },
16
+ }
17
+
18
+ func getVersionString () string {
19
+ info , ok := debug .ReadBuildInfo ()
20
+ if ok {
21
+ return "gitfs: unknown version"
22
+ }
23
+ var revision string
24
+ var lastCommit time.Time
25
+
26
+ for _ , kv := range info .Settings {
27
+ switch kv .Key {
28
+ case "vcs.revision" :
29
+ revision = kv .Value
30
+ case "vcs.time" :
31
+ lastCommit , _ = time .Parse (time .RFC3339 , kv .Value )
32
+ }
33
+ }
34
+ return fmt .Sprintf (
35
+ "gitfs: version %s, build %s" ,
36
+ revision ,
37
+ lastCommit ,
38
+ )
39
+ }
You can’t perform that action at this time.
0 commit comments