github.com/ava-labs/avalanchego@v1.11.11/vms/example/xsvm/cmd/versionjson/cmd.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package versionjson 5 6 import ( 7 "encoding/json" 8 "fmt" 9 10 "github.com/spf13/cobra" 11 12 "github.com/ava-labs/avalanchego/ids" 13 "github.com/ava-labs/avalanchego/utils/constants" 14 "github.com/ava-labs/avalanchego/version" 15 "github.com/ava-labs/avalanchego/vms/example/xsvm" 16 ) 17 18 type vmVersions struct { 19 Name string `json:"name"` 20 VMID ids.ID `json:"vmid"` 21 Version *version.Semantic `json:"version"` 22 RPCChainVM uint64 `json:"rpcchainvm"` 23 } 24 25 func Command() *cobra.Command { 26 return &cobra.Command{ 27 Use: "version-json", 28 Short: "Prints out the version in json format", 29 RunE: versionFunc, 30 } 31 } 32 33 func versionFunc(*cobra.Command, []string) error { 34 versions := vmVersions{ 35 Name: constants.XSVMName, 36 VMID: constants.XSVMID, 37 Version: xsvm.Version, 38 RPCChainVM: uint64(version.RPCChainVMProtocol), 39 } 40 jsonBytes, err := json.MarshalIndent(versions, "", " ") 41 if err != nil { 42 return fmt.Errorf("failed to marshal versions: %w", err) 43 } 44 fmt.Println(string(jsonBytes)) 45 return nil 46 }