From 44fb418f3591c30d9f7899f72d7519437bc8bd77 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Thu, 14 Sep 2017 11:41:48 +0100 Subject: [PATCH] main: Avoid duplication in makeVersionString() Simplified makeVersionString() to avoid duplicating string literals. Fixes #554. Signed-off-by: James O. D. Hunt --- main.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 54a5e0b7..5b0aac3d 100644 --- a/main.go +++ b/main.go @@ -199,24 +199,27 @@ func commandNotFound(c *cli.Context, command string) { func makeVersionString() string { v := make([]string, 0, 3) - if version != "" { - v = append(v, name+" : "+version) - } else { - v = append(v, name+" : "+unknown) + versionStr := version + if versionStr == "" { + versionStr = unknown } - if commit != "" { - v = append(v, " commit : "+commit) - } else { - v = append(v, " commit : "+unknown) + v = append(v, name+" : "+versionStr) + + commitStr := commit + if commitStr == "" { + commitStr = unknown } - if specs.Version != "" { - v = append(v, " OCI specs: "+specs.Version) - } else { - v = append(v, " OCI specs: "+unknown) + v = append(v, " commit : "+commitStr) + + specVersionStr := specs.Version + if specVersionStr == "" { + specVersionStr = unknown } + v = append(v, " OCI specs: "+specVersionStr) + return strings.Join(v, "\n") }