Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"jf docker scan" panic fix #1291

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
dortam888 marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading