@@ -3,70 +3,73 @@ package core
33import (
44 "encoding/json"
55 "fmt"
6- "runtime"
76 "strings"
87
9- "github.com/altuslabsxyz/devnet-builder/internal"
108 "github.com/altuslabsxyz/devnet-builder/internal/infrastructure/network"
9+ "github.com/altuslabsxyz/devnet-builder/internal/version"
1110 "github.com/altuslabsxyz/devnet-builder/types/ctxconfig"
1211 "github.com/spf13/cobra"
1312)
1413
15- // VersionInfo contains version details.
16- type VersionInfo struct {
17- Version string `json:"version"`
18- GitCommit string `json:"git_commit"`
19- BuildDate string `json:"build_date"`
20- GoVersion string `json:"go_version"`
21- Platform string `json:"platform"`
22- BuildNetworks string `json:"build_networks"`
23- Networks []string `json:"networks"` // Actual registered networks
14+ // ExtendedVersionInfo contains version details with network plugin info.
15+ type ExtendedVersionInfo struct {
16+ version.Info `yaml:",inline"`
17+ Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"`
2418}
2519
2620// NewVersionCmd creates the version command.
2721func NewVersionCmd () * cobra.Command {
22+ var long bool
23+
2824 cmd := & cobra.Command {
2925 Use : "version" ,
3026 Short : "Show version information" ,
31- Long : "Show version information including build details." ,
32- RunE : runVersion ,
33- }
27+ Long : "Show version information including build details. Use --long for detailed dependency info." ,
28+ RunE : func (cmd * cobra.Command , args []string ) error {
29+ cfg := ctxconfig .FromContext (cmd .Context ())
30+ jsonMode := cfg .JSONMode ()
3431
35- return cmd
36- }
32+ // Get actual registered networks
33+ registeredNetworks := network . List ()
3734
38- func runVersion (cmd * cobra.Command , args []string ) error {
39- cfg := ctxconfig .FromContext (cmd .Context ())
40- jsonMode := cfg .JSONMode ()
35+ // Create base version info
36+ info := version .NewInfo ("devnet-builder" , "devnet-builder" )
37+ if long {
38+ info = info .WithBuildDeps ()
39+ }
4140
42- // Get actual registered networks
43- registeredNetworks := network .List ()
41+ // Extend with network info
42+ extInfo := ExtendedVersionInfo {
43+ Info : info ,
44+ Networks : registeredNetworks ,
45+ }
4446
45- info := VersionInfo {
46- Version : internal .Version ,
47- GitCommit : internal .GitCommit ,
48- BuildDate : internal .BuildDate ,
49- GoVersion : runtime .Version (),
50- Platform : fmt .Sprintf ("%s/%s" , runtime .GOOS , runtime .GOARCH ),
51- BuildNetworks : "plugin-based" ,
52- Networks : registeredNetworks ,
53- }
47+ if jsonMode {
48+ data , err := json .MarshalIndent (extInfo , "" , " " )
49+ if err != nil {
50+ return err
51+ }
52+ fmt .Println (string (data ))
53+ return nil
54+ }
55+
56+ if long {
57+ fmt .Print (extInfo .Info .LongString ())
58+ if len (registeredNetworks ) > 0 {
59+ fmt .Printf ("networks: %s\n " , strings .Join (registeredNetworks , ", " ))
60+ }
61+ } else {
62+ fmt .Print (extInfo .Info .String ())
63+ if len (registeredNetworks ) > 0 {
64+ fmt .Printf (" networks: %s\n " , strings .Join (registeredNetworks , ", " ))
65+ }
66+ }
5467
55- if jsonMode {
56- data , err := json .MarshalIndent (info , "" , " " )
57- if err != nil {
58- return err
59- }
60- fmt .Println (string (data ))
61- return nil
68+ return nil
69+ },
6270 }
6371
64- fmt .Printf ("devnet-builder %s\n " , info .Version )
65- fmt .Printf (" Git commit: %s\n " , info .GitCommit )
66- fmt .Printf (" Build date: %s\n " , info .BuildDate )
67- fmt .Printf (" Go version: %s\n " , info .GoVersion )
68- fmt .Printf (" Platform: %s\n " , info .Platform )
69- fmt .Printf (" Networks: %s\n " , strings .Join (registeredNetworks , ", " ))
72+ cmd .Flags ().BoolVar (& long , "long" , false , "Show detailed version info including build dependencies" )
7073
71- return nil
74+ return cmd
7275}
0 commit comments