From ce9b4eb809f7f932e41154d04fca8674532b9d19 Mon Sep 17 00:00:00 2001 From: Roy Lee Date: Tue, 24 May 2022 10:50:06 -0700 Subject: [PATCH] [lbry] version: use version package --- config.go | 3 +- lbcwallet.go | 4 ++- version.go | 77 ---------------------------------------------------- 3 files changed, 5 insertions(+), 79 deletions(-) delete mode 100644 version.go diff --git a/config.go b/config.go index b82ddbe..a092f4b 100644 --- a/config.go +++ b/config.go @@ -18,6 +18,7 @@ import ( flags "github.com/jessevdk/go-flags" "github.com/lbryio/lbcd/chaincfg" + "github.com/lbryio/lbcd/version" btcutil "github.com/lbryio/lbcutil" "github.com/lbryio/lbcwallet/internal/cfgutil" "github.com/lbryio/lbcwallet/internal/legacy/keystore" @@ -296,7 +297,7 @@ func loadConfig() (*config, []string, error) { appName = strings.TrimSuffix(appName, filepath.Ext(appName)) usageMessage := fmt.Sprintf("Use %s -h to show usage", appName) if preCfg.ShowVersion { - fmt.Println(appName, "version", version()) + fmt.Println(appName, "version", version.Full()) os.Exit(0) } diff --git a/lbcwallet.go b/lbcwallet.go index d0c6f14..b36ed2e 100644 --- a/lbcwallet.go +++ b/lbcwallet.go @@ -16,6 +16,8 @@ import ( "github.com/lbryio/lbcwallet/chain" "github.com/lbryio/lbcwallet/rpc/legacyrpc" "github.com/lbryio/lbcwallet/wallet" + + "github.com/lbryio/lbcd/version" ) var ( @@ -52,7 +54,7 @@ func walletMain() error { }() // Show version at startup. - log.Infof("Version %s", version()) + log.Infof("Version %s", version.Full()) if cfg.Profile != "" { go func() { diff --git a/version.go b/version.go deleted file mode 100644 index 4fa6a24..0000000 --- a/version.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2013-2014 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package main - -import ( - "bytes" - "fmt" - "strings" -) - -// semanticAlphabet -const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-" - -// These constants define the application version and follow the semantic -// versioning 2.0.0 spec (http://semver.org/). -const ( - appMajor uint = 0 - appMinor uint = 11 - appPatch uint = 0 - - // appPreRelease MUST only contain characters from semanticAlphabet - // per the semantic versioning spec. - appPreRelease = "alpha" -) - -// appBuild is defined as a variable so it can be overridden during the build -// process with '-ldflags "-X main.appBuild foo' if needed. It MUST only -// contain characters from semanticAlphabet per the semantic versioning spec. -var appBuild string - -// version returns the application version as a properly formed string per the -// semantic versioning 2.0.0 spec (http://semver.org/). -func version() string { - // Start with the major, minor, and path versions. - version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch) - - // Append pre-release version if there is one. The hyphen called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the pre-release string. The pre-release version - // is not appended if it contains invalid characters. - preRelease := normalizeVerString(appPreRelease) - if preRelease != "" { - version = fmt.Sprintf("%s-%s", version, preRelease) - } - - // Append build metadata if there is any. The plus called for - // by the semantic versioning spec is automatically appended and should - // not be contained in the build metadata string. The build metadata - // string is not appended if it contains invalid characters. - build := normalizeVerString(appBuild) - if build != "" { - version = fmt.Sprintf("%s+%s", version, build) - } - - return version -} - -// normalizeVerString returns the passed string stripped of all characters which -// are not valid according to the semantic versioning guidelines for pre-release -// version and build metadata strings. In particular they MUST only contain -// characters in semanticAlphabet. -func normalizeVerString(str string) string { - result := bytes.Buffer{} - for _, r := range str { - if strings.ContainsRune(semanticAlphabet, r) { - _, err := result.WriteRune(r) - // Writing to a bytes.Buffer panics on OOM, and all - // errors are unexpected. - if err != nil { - panic(err) - } - } - } - return result.String() -}