Set version to unknown if not set (#4521)

This commit is contained in:
Daniel Nelson 2018-08-12 16:52:35 -07:00 committed by GitHub
parent 98a785b077
commit 31e1c04ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 21 deletions

View File

@ -58,22 +58,11 @@ var fService = flag.String("service", "",
var fRunAsConsole = flag.Bool("console", false, "run as console application (windows only)")
var (
nextVersion = "1.8.0"
version string
commit string
branch string
version string
commit string
branch string
)
func init() {
// If commit or branch are not set, make that clear.
if commit == "" {
commit = "unknown"
}
if branch == "" {
branch = "unknown"
}
}
var stop chan struct{}
func reloadLoop(
@ -165,7 +154,7 @@ func reloadLoop(
}
}()
log.Printf("I! Starting Telegraf %s\n", displayVersion())
log.Printf("I! Starting Telegraf %s\n", version)
log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " "))
log.Printf("I! Loaded aggregators: %s", strings.Join(c.AggregatorNames(), " "))
log.Printf("I! Loaded processors: %s", strings.Join(c.ProcessorNames(), " "))
@ -225,11 +214,27 @@ func (p *program) Stop(s service.Service) error {
return nil
}
func displayVersion() string {
if version == "" {
return fmt.Sprintf("v%s~%s", nextVersion, commit)
func formatFullVersion() string {
var parts = []string{"Telegraf"}
if version != "" {
parts = append(parts, version)
} else {
parts = append(parts, "unknown")
}
return "v" + version
if branch != "" || commit != "" {
if branch == "" {
branch = "unknown"
}
if commit == "" {
commit = "unknown"
}
git := fmt.Sprintf("(git: %s %s)", branch, commit)
parts = append(parts, git)
}
return strings.Join(parts, " ")
}
func main() {
@ -273,7 +278,7 @@ func main() {
if len(args) > 0 {
switch args[0] {
case "version":
fmt.Printf("Telegraf %s (git: %s %s)\n", displayVersion(), branch, commit)
fmt.Println(formatFullVersion())
return
case "config":
config.PrintSampleConfig(
@ -301,7 +306,7 @@ func main() {
}
return
case *fVersion:
fmt.Printf("Telegraf %s (git: %s %s)\n", displayVersion(), branch, commit)
fmt.Println(formatFullVersion())
return
case *fSampleConfig:
config.PrintSampleConfig(