Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): add alias to node version #1281

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/daemon/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_about.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var NodeVersion = Version{
Minor: 2,
Patch: 0,
Meta: "beta",
Alias: "",
}

// Version defines the version of Pactus software.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading