Skip to content

Commit

Permalink
feat(version): add alias to node version
Browse files Browse the repository at this point in the history
  • Loading branch information
ambersun1234 committed May 24, 2024
1 parent cfc28ae commit e8c0c3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
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

0 comments on commit e8c0c3d

Please sign in to comment.