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 {
3434 auth.UserCommands
3535 auth.TokenCommands
3636 auth.AuthCommands
37+ VersionCommands
3738}
3839
3940///////////////////////////////////////////////////////////////////////////////
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 11package version
22
3+ import "runtime"
4+
35///////////////////////////////////////////////////////////////////////////////
46// GLOBALS
57
1012 GitHash string
1113 GoBuildTime string
1214)
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