Skip to content

Commit

Permalink
Merge pull request #1510 from ConnorJC3/fix-version
Browse files Browse the repository at this point in the history
Fix --version output
  • Loading branch information
k8s-ci-robot authored Feb 13, 2023
2 parents c4baaa7 + 46d00ca commit 531d6bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ func GetOptions(fs *flag.FlagSet) *Options {
}

if *version {
info, err := driver.GetVersionJSON()
versionInfo, err := driver.GetVersionJSON()
if err != nil {
klog.ErrorS(err, "failed to get version", "version", info)
klog.ErrorS(err, "failed to get version")
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
}
fmt.Println(versionInfo)
osExit(0)
}

if *toStderr {
Expand Down
5 changes: 5 additions & 0 deletions cmd/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ func TestGetOptions(t *testing.T) {
defer func() { osExit = oldOSExit }()

var exitCode int
calledExit := false
testExit := func(code int) {
exitCode = code
calledExit = true
}
osExit = testExit

Expand All @@ -181,6 +183,9 @@ func TestGetOptions(t *testing.T) {
if exitCode != 0 {
t.Fatalf("expected exit code 0 but got %d", exitCode)
}
if !calledExit {
t.Fatalf("expect osExit to be called, but wasn't")
}
},
},
}
Expand Down

0 comments on commit 531d6bb

Please sign in to comment.