Skip to content

Commit 38e1fdf

Browse files
fix: handle abs path in subject when getting nerdctl version (#280)
Signed-off-by: Swapnanil Gupta <[email protected]>
1 parent 2279f8e commit 38e1fdf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

option/option.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"os"
1111
"os/exec"
12+
"path/filepath"
1213
"regexp"
1314
"strings"
1415
)
@@ -141,7 +142,8 @@ func (o *Option) Subject() []string {
141142

142143
// GetNerdctlVersion gets the nerdctl version from the subject. If the subject is neither "nerdctl" nor "finch", it will return an error.
143144
func (o *Option) GetNerdctlVersion() (string, error) {
144-
switch o.subject[0] {
145+
execName := filepath.Base(o.subject[0])
146+
switch execName {
145147
case "nerdctl":
146148
//nolint:gosec // G204 is not an issue because subject is fully controlled by the user.
147149
versionBytes, err := exec.Command(o.subject[0], "--version").Output()
@@ -165,7 +167,7 @@ func (o *Option) GetNerdctlVersion() (string, error) {
165167
}
166168
return version, nil
167169
default:
168-
return "", fmt.Errorf("unsupported subject %s", o.subject[0])
170+
return "", fmt.Errorf("unsupported subject %s", execName)
169171
}
170172
}
171173

0 commit comments

Comments
 (0)