Skip to content

Commit bea3f68

Browse files
committed
feat: add version cmd to devnetd and update dvb
1 parent 4533d51 commit bea3f68

3 files changed

Lines changed: 91 additions & 49 deletions

File tree

cmd/devnet-builder/commands/core/version.go

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,73 @@ package core
33
import (
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.
2721
func 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
}

cmd/devnetd/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88

99
"github.com/altuslabsxyz/devnet-builder/internal/daemon/server"
10+
"github.com/altuslabsxyz/devnet-builder/internal/version"
1011
"github.com/spf13/cobra"
1112
)
1213

@@ -35,6 +36,9 @@ func main() {
3536
rootCmd.Flags().BoolVar(&config.EnableDocker, "docker", false, "Enable Docker container runtime")
3637
rootCmd.Flags().StringVar(&config.DockerImage, "docker-image", "stablelabs/stabled:latest", "Default Docker image for nodes")
3738

39+
// Add version command
40+
rootCmd.AddCommand(version.NewCmd("devnet-builder", "devnetd"))
41+
3842
if err := rootCmd.Execute(); err != nil {
3943
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
4044
os.Exit(1)

cmd/dvb/main.go

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
v1 "github.com/altuslabsxyz/devnet-builder/api/proto/gen/v1"
1010
"github.com/altuslabsxyz/devnet-builder/internal/client"
11+
"github.com/altuslabsxyz/devnet-builder/internal/version"
1112
"github.com/fatih/color"
1213
"github.com/spf13/cobra"
1314
)
@@ -77,18 +78,52 @@ func main() {
7778
}
7879

7980
func newVersionCmd() *cobra.Command {
80-
return &cobra.Command{
81+
var (
82+
long bool
83+
jsonOutput bool
84+
)
85+
86+
cmd := &cobra.Command{
8187
Use: "version",
8288
Short: "Print version information",
83-
Run: func(cmd *cobra.Command, args []string) {
84-
fmt.Println("dvb version 0.1.0")
89+
Long: "Print version information including build details. Use --long for detailed dependency info.",
90+
RunE: func(cmd *cobra.Command, args []string) error {
91+
info := version.NewInfo("devnet-builder", "dvb")
92+
93+
if long {
94+
info = info.WithBuildDeps()
95+
}
96+
97+
if jsonOutput {
98+
output, err := info.JSON()
99+
if err != nil {
100+
return err
101+
}
102+
fmt.Println(output)
103+
return nil
104+
}
105+
106+
if long {
107+
fmt.Print(info.LongString())
108+
} else {
109+
fmt.Print(info.String())
110+
}
111+
112+
// Show connection mode (dvb-specific feature)
85113
if daemonClient != nil {
86-
fmt.Println("Mode: daemon")
114+
fmt.Println("mode: daemon")
87115
} else {
88-
fmt.Println("Mode: standalone")
116+
fmt.Println("mode: standalone")
89117
}
118+
119+
return nil
90120
},
91121
}
122+
123+
cmd.Flags().BoolVar(&long, "long", false, "Show detailed version info including build dependencies")
124+
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output version info in JSON format")
125+
126+
return cmd
92127
}
93128

94129
func newDaemonCmd() *cobra.Command {

0 commit comments

Comments
 (0)