File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ type CLI struct {
34
34
auth.UserCommands
35
35
auth.TokenCommands
36
36
auth.AuthCommands
37
+ VersionCommands
37
38
}
38
39
39
40
///////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+
7
+ // Packages
8
+ server "github.com/mutablelogic/go-server"
9
+ version "github.com/mutablelogic/go-server/pkg/version"
10
+ )
11
+
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+ // TYPES
14
+
15
+ type VersionCommands struct {
16
+ Version VersionCommand `cmd:"" group:"MISC" help:"Print version information"`
17
+ }
18
+
19
+ type VersionCommand struct {}
20
+
21
+ ///////////////////////////////////////////////////////////////////////////////
22
+ // PUBLIC METHODS
23
+
24
+ func (cmd * VersionCommand ) Run (app server.Cmd ) error {
25
+ // Print version information
26
+ data , err := json .MarshalIndent (version .Map (), "" , " " )
27
+ if err != nil {
28
+ return err
29
+ }
30
+ fmt .Println (string (data ))
31
+ return nil
32
+ }
Original file line number Diff line number Diff line change 1
1
package version
2
2
3
+ import "runtime"
4
+
3
5
///////////////////////////////////////////////////////////////////////////////
4
6
// GLOBALS
5
7
10
12
GitHash string
11
13
GoBuildTime string
12
14
)
15
+
16
+ ////////////////////////////////////////////////////////////////////////////////
17
+ // PRIVATE METHODS
18
+
19
+ func Map () map [string ]any {
20
+ vars := map [string ]any {}
21
+ if GitSource != "" {
22
+ vars ["source" ] = GitSource
23
+ }
24
+ if GitTag != "" || GitBranch != "" {
25
+ vars ["version" ] = GitTag
26
+ vars ["branch" ] = GitBranch
27
+ vars ["hash" ] = GitHash
28
+ }
29
+ if GoBuildTime != "" {
30
+ vars ["build" ] = GoBuildTime
31
+ }
32
+ vars ["go" ] = runtime .Version ()
33
+ vars ["os" ] = runtime .GOOS
34
+ vars ["arch" ] = runtime .GOARCH
35
+ return vars
36
+ }
You can’t perform that action at this time.
0 commit comments