mirror of
https://github.com/safing/portbase
synced 2025-09-04 11:40:23 +00:00
Upgrade info for wider program support
This commit is contained in:
parent
52b56450c7
commit
0a4f97d7fa
4 changed files with 20 additions and 8 deletions
|
@ -36,7 +36,7 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Set Info
|
// Set Info
|
||||||
info.Set("Portbase API Development Helper", "0.0.1")
|
info.Set("Portbase API Development Helper", "0.0.1", "GPLv3", false)
|
||||||
|
|
||||||
// Register some dummy config vars
|
// Register some dummy config vars
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ func CheckVersion() error {
|
||||||
if name == "[NAME]" ||
|
if name == "[NAME]" ||
|
||||||
version == "[version unknown]" ||
|
version == "[version unknown]" ||
|
||||||
commit == "[commit unknown]" ||
|
commit == "[commit unknown]" ||
|
||||||
|
license == "[license unknown]" ||
|
||||||
buildOptions == "[options unknown]" ||
|
buildOptions == "[options unknown]" ||
|
||||||
buildUser == "[user unknown]" ||
|
buildUser == "[user unknown]" ||
|
||||||
buildHost == "[host unknown]" ||
|
buildHost == "[host unknown]" ||
|
||||||
|
|
|
@ -10,16 +10,21 @@ var (
|
||||||
name = "[NAME]"
|
name = "[NAME]"
|
||||||
version = "[version unknown]"
|
version = "[version unknown]"
|
||||||
commit = "[commit unknown]"
|
commit = "[commit unknown]"
|
||||||
|
license = "[license unknown]"
|
||||||
buildOptions = "[options unknown]"
|
buildOptions = "[options unknown]"
|
||||||
buildUser = "[user unknown]"
|
buildUser = "[user unknown]"
|
||||||
buildHost = "[host unknown]"
|
buildHost = "[host unknown]"
|
||||||
buildDate = "[date unknown]"
|
buildDate = "[date unknown]"
|
||||||
buildSource = "[source unknown]"
|
buildSource = "[source unknown]"
|
||||||
|
|
||||||
|
compareVersion bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Info holds the programs meta information.
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Name string
|
Name string
|
||||||
Version string
|
Version string
|
||||||
|
License string
|
||||||
Commit string
|
Commit string
|
||||||
BuildOptions string
|
BuildOptions string
|
||||||
BuildUser string
|
BuildUser string
|
||||||
|
@ -28,16 +33,21 @@ type Info struct {
|
||||||
BuildSource string
|
BuildSource string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Set(setName string, setVersion string) {
|
// Set sets meta information via the main routine. This should be the first thing your program calls.
|
||||||
|
func Set(setName string, setVersion string, setLicenseName string, compareVersionToTag bool) {
|
||||||
name = setName
|
name = setName
|
||||||
version = setVersion
|
version = setVersion
|
||||||
|
license = setLicenseName
|
||||||
|
compareVersion = compareVersionToTag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInfo returns all the meta information about the program.
|
||||||
func GetInfo() *Info {
|
func GetInfo() *Info {
|
||||||
return &Info{
|
return &Info{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: version,
|
Version: version,
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
|
License: license,
|
||||||
BuildOptions: buildOptions,
|
BuildOptions: buildOptions,
|
||||||
BuildUser: buildUser,
|
BuildUser: buildUser,
|
||||||
BuildHost: buildHost,
|
BuildHost: buildHost,
|
||||||
|
@ -46,17 +56,18 @@ func GetInfo() *Info {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version returns the short version string.
|
||||||
func Version() string {
|
func Version() string {
|
||||||
if strings.HasPrefix(commit, fmt.Sprintf("tags/v%s-0-", version)) {
|
if !compareVersion || strings.HasPrefix(commit, fmt.Sprintf("tags/v%s-0-", version)) {
|
||||||
return version
|
return version
|
||||||
} else {
|
|
||||||
return version + "*"
|
|
||||||
}
|
}
|
||||||
|
return version + "*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FullVersion returns the full and detailed version string.
|
||||||
func FullVersion() string {
|
func FullVersion() string {
|
||||||
s := ""
|
s := ""
|
||||||
if strings.HasPrefix(commit, fmt.Sprintf("tags/v%s-0-", version)) {
|
if !compareVersion || strings.HasPrefix(commit, fmt.Sprintf("tags/v%s-0-", version)) {
|
||||||
s += fmt.Sprintf("%s\nversion %s\n", name, version)
|
s += fmt.Sprintf("%s\nversion %s\n", name, version)
|
||||||
} else {
|
} else {
|
||||||
s += fmt.Sprintf("%s\ndevelopment build, built on top version %s\n", name, version)
|
s += fmt.Sprintf("%s\ndevelopment build, built on top version %s\n", name, version)
|
||||||
|
@ -66,6 +77,6 @@ func FullVersion() string {
|
||||||
s += fmt.Sprintf(" using options %s\n", strings.Replace(buildOptions, "§", " ", -1))
|
s += fmt.Sprintf(" using options %s\n", strings.Replace(buildOptions, "§", " ", -1))
|
||||||
s += fmt.Sprintf(" by %s@%s\n", buildUser, buildHost)
|
s += fmt.Sprintf(" by %s@%s\n", buildUser, buildHost)
|
||||||
s += fmt.Sprintf(" on %s\n", buildDate)
|
s += fmt.Sprintf(" on %s\n", buildDate)
|
||||||
s += fmt.Sprintf("\nLicensed under the AGPL license.\nThe source code is available here: %s", buildSource)
|
s += fmt.Sprintf("\nLicensed under the %s license.\nThe source code is available here: %s", license, buildSource)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Set Info
|
// Set Info
|
||||||
info.Set("Portbase", "0.0.1")
|
info.Set("Portbase", "0.0.1", "GPLv3", false)
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
err := modules.Start()
|
err := modules.Start()
|
||||||
|
|
Loading…
Add table
Reference in a new issue