Skip to content

Commit

Permalink
main: Avoid duplication in makeVersionString()
Browse files Browse the repository at this point in the history
Simplified makeVersionString() to avoid duplicating string literals.

Fixes clearcontainers#554.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 15, 2017
1 parent 0f8ec51 commit 44fb418
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 44fb418

Please sign in to comment.