-
-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
-v/--version
flag to print version string (#3883)
* Add `-v/--version` flag to print version string - Created a new flag `-v/--version` in the command-line interface to display the version number and exit. - Moved all version-related functions inside the config package to the new file `manager/config/version.go` to avoid circular dependencies. - Added a new `GetVersionString()` function to generate a formatted version string. - Updated references to the moved version functions. - Updated references in the `Makefile`. * Move version embeds to build package * Remove githash var --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
- Loading branch information
1 parent
969af2a
commit 0c0ba19
Showing
8 changed files
with
79 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package build | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var version string | ||
var buildstamp string | ||
var githash string | ||
var officialBuild string | ||
|
||
func Version() (string, string, string) { | ||
return version, githash, buildstamp | ||
} | ||
|
||
func VersionString() string { | ||
var versionString string | ||
switch { | ||
case version != "": | ||
if githash != "" && !IsDevelop() { | ||
versionString = version + " (" + githash + ")" | ||
} else { | ||
versionString = version | ||
} | ||
case githash != "": | ||
versionString = githash | ||
default: | ||
versionString = "unknown" | ||
} | ||
if IsOfficial() { | ||
versionString += " - Official Build" | ||
} else { | ||
versionString += " - Unofficial Build" | ||
} | ||
if buildstamp != "" { | ||
versionString += " - " + buildstamp | ||
} | ||
return versionString | ||
} | ||
|
||
func IsOfficial() bool { | ||
return officialBuild == "true" | ||
} | ||
|
||
func IsDevelop() bool { | ||
if githash == "" { | ||
return false | ||
} | ||
|
||
// if the version is suffixed with -x-xxxx, then we are running a development build | ||
develop := false | ||
re := regexp.MustCompile(`-\d+-g\w+$`) | ||
if re.MatchString(version) { | ||
develop = true | ||
} | ||
return develop | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters