From e8c0c3dbeec638c1e3a9663ad6eb1b87cdcd0bf6 Mon Sep 17 00:00:00 2001 From: Shawn Hsu Date: Sat, 25 May 2024 00:13:06 +0800 Subject: [PATCH] feat(version): add alias to node version --- cmd/daemon/version.go | 2 +- cmd/gtk/dialog_about.go | 2 +- node/node.go | 2 +- version/version.go | 11 +++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/daemon/version.go b/cmd/daemon/version.go index 4ec22c0e8..d3b6ff040 100644 --- a/cmd/daemon/version.go +++ b/cmd/daemon/version.go @@ -13,6 +13,6 @@ func buildVersionCmd(parentCmd *cobra.Command) { } parentCmd.AddCommand(versionCmd) versionCmd.Run = func(c *cobra.Command, _ []string) { - c.Printf("Pactus version: %s\n", version.NodeVersion) + c.Printf("Pactus version: %s\n", version.NodeVersion.StringWithAlias()) } } diff --git a/cmd/gtk/dialog_about.go b/cmd/gtk/dialog_about.go index 9288dc033..e6a04fd7c 100644 --- a/cmd/gtk/dialog_about.go +++ b/cmd/gtk/dialog_about.go @@ -28,7 +28,7 @@ func aboutDialog() *gtk.AboutDialog { fatalErrorCheck(err) dlg.SetLogo(pxLogo) - dlg.SetVersion(version.NodeVersion.String()) + dlg.SetVersion(version.NodeVersion.StringWithAlias()) return dlg } diff --git a/node/node.go b/node/node.go index cdca3dfba..3ff0f80b0 100644 --- a/node/node.go +++ b/node/node.go @@ -50,7 +50,7 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config, chainType := genDoc.ChainType() logger.Info("You are running a Pactus blockchain", - "version", version.NodeVersion, + "version", version.NodeVersion.StringWithAlias(), "network", chainType) messageCh := make(chan message.Message, 500) diff --git a/version/version.go b/version/version.go index 0e1e50b2e..fd56afa90 100644 --- a/version/version.go +++ b/version/version.go @@ -17,6 +17,7 @@ var NodeVersion = Version{ Minor: 2, Patch: 0, Meta: "beta", + Alias: "", } // Version defines the version of Pactus software. @@ -26,6 +27,7 @@ type Version struct { Minor uint // Minor version number Patch uint // Patch version number Meta string // Metadata for version (e.g., "beta", "rc1") + Alias string // Alias for version (e.g., "London") } // ParseVersion parses a version string into a Version struct. @@ -76,6 +78,15 @@ func ParseVersion(versionStr string) (Version, error) { return v, nil } +// StringWithAlias returns a string representation of the Version object with the alias. +func (v Version) StringWithAlias() string { + if v.Alias == "" { + return v.String() + } + + return fmt.Sprintf("%s (%s)", v.String(), v.Alias) +} + // String returns a string representation of the Version object. func (v Version) String() string { version := fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)