Skip to content

Commit

Permalink
"jf docker scan" panic fix (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
dortam888 authored Nov 4, 2024
1 parent 7d70e2d commit 3029fdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
14 changes: 8 additions & 6 deletions plugins/components/conversionlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/jfrog/gofrog/datastructures"
"github.com/jfrog/jfrog-cli-core/v2/docs/common"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -80,7 +79,7 @@ func convertCommand(cmd Command, namespaces ...string) (cli.Command, error) {
if err != nil {
return cli.Command{}, err
}
return cli.Command{
cliCmd := cli.Command{
Name: cmd.Name,
Flags: convertedFlags,
Aliases: cmd.Aliases,
Expand All @@ -93,9 +92,12 @@ func convertCommand(cmd Command, namespaces ...string) (cli.Command, error) {
BashComplete: common.CreateBashCompletionFunc(),
SkipFlagParsing: cmd.SkipFlagParsing,
Hidden: cmd.Hidden,
}
if cmd.Action != nil {
// Passing any other interface than 'cli.ActionFunc' will fail the command.
Action: getActionFunc(cmd),
}, nil
cliCmd.Action = getActionFunc(cmd)
}
return cliCmd, nil
}

func removeEmptyValues(slice []string) []string {
Expand All @@ -112,8 +114,8 @@ func removeEmptyValues(slice []string) []string {
func createCommandUsages(cmd Command, convertedStringFlags map[string]StringFlag, namespaces ...string) (usages []string, err error) {
// Handle manual usages provided.
if cmd.UsageOptions != nil {
for _, manualUsage := range cmd.UsageOptions.Usage {
usages = append(usages, fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), manualUsage))
if cmd.UsageOptions.Usage != nil {
usages = append(usages, cmd.UsageOptions.Usage...)
}
if cmd.UsageOptions.ReplaceAutoGeneratedUsage {
return
Expand Down
10 changes: 2 additions & 8 deletions plugins/components/conversionlayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
Expand All @@ -20,11 +19,6 @@ func TestCreateCommandUsages(t *testing.T) {
strFlag := NewStringFlag("flag", "", SetMandatory())

override := []string{"usage override", "usage override 2", "usage override 3"}
expectedOverride := []string{
fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), "usage override"),
fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), "usage override 2"),
fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), "usage override 3"),
}

tests := []struct {
name string
Expand Down Expand Up @@ -93,7 +87,7 @@ func TestCreateCommandUsages(t *testing.T) {
UsageOptions: &UsageOptions{Usage: override},
},
stringFlags: map[string]StringFlag{optStrFlag.Name: optStrFlag},
expected: append(expectedOverride,
expected: append(override,
fmt.Sprintf("%s [command options] <%s> <%s>", expectedPrefix, "first argument", "second"),
fmt.Sprintf("%s [command options] --%s=<%s> <%s>", expectedPrefix, optStrFlag.Name, optStrFlag.HelpValue, "first argument"),
),
Expand All @@ -107,7 +101,7 @@ func TestCreateCommandUsages(t *testing.T) {
UsageOptions: &UsageOptions{Usage: override, ReplaceAutoGeneratedUsage: true},
},
stringFlags: map[string]StringFlag{optStrFlag.Name: optStrFlag, strFlag.Name: strFlag},
expected: expectedOverride,
expected: override, // override is not expected to be changed upon using UsageOptions
},
}

Expand Down

0 comments on commit 3029fdc

Please sign in to comment.