Skip to content
Open
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
25 changes: 24 additions & 1 deletion buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/BurntSushi/toml"
"github.com/jfrog/gofrog/datastructures"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container/strategies"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
Expand Down Expand Up @@ -427,7 +428,7 @@ func GetCommands() []cli.Command {
},
{
Name: "docker",
Flags: cliutils.GetCommandFlags(cliutils.Docker),
Flags: getDockerFlags(),
Usage: docker.GetDescription(),
HelpName: corecommon.CreateUsage("docker", docker.GetDescription(), docker.Usage),
UsageText: docker.GetArguments(),
Expand Down Expand Up @@ -496,6 +497,28 @@ func skipFlagParsingForDockerCmd() bool {
return true
}

func getDockerFlags() []cli.Flag {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

flagNames := datastructures.MakeSet[string]()
// Collecting existing Docker flags
flagList := cliutils.GetCommandFlags(cliutils.Docker)
for _, f := range flagList {
flagNames.Add(f.GetName())
}
// Adding `Docker Scan` flags
converted, _, err := components.ConvertFlags(securityDocs.DockerScan, securityDocs.GetCommandFlags(securityDocs.DockerScan))
if err != nil {
log.Error("Could not convert Docker Scan flags:", err)
return flagList
}
for _, f := range converted {
// Avoiding flag duplication which causes panic in urfave/cli
if !flagNames.Exists(f.GetName()) {
flagList = append(flagList, f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use flagNames in the whole method and then convert it to slice ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do it, when converting to slice you will need to go over the 2 sources of flags to locate where it is.
flagNames used only so we can validate quick if a flag already exist. I can switch it to just check if the slice contains the value and remove flagNames from the func... IMO its ok like this

}
}
return flagList
}

// decorateWithFlagCapture injects a Before hook into every command returned from this package,
// so we can capture user-provided flags consistently in one place for all build commands.
func decorateWithFlagCapture(cmds []cli.Command) []cli.Command {
Expand Down
40 changes: 40 additions & 0 deletions buildtools/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"testing"

securityDocs "github.com/jfrog/jfrog-cli-security/cli/docs"
"github.com/jfrog/jfrog-cli/utils/cliutils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -274,3 +276,41 @@ func TestExtractDockerBuildOptionsFromArgs(t *testing.T) {
})
}
}

func TestGetDockerFlags(t *testing.T) {
flags := getDockerFlags()

// Check expected flags from CLI
commonFlagList := cliutils.GetCommandFlags(cliutils.Docker)
for _, commonFlag := range commonFlagList {
found := false
for _, flag := range flags {
if flag.GetName() == commonFlag.GetName() {
found = true
break
}
}
assert.Truef(t, found, "Expected flag '%s' from CLI not found in docker flags", commonFlag.GetName())
}

// Check expected flags from Security commands
secFlags := securityDocs.GetCommandFlags(securityDocs.DockerScan)
for _, secFlag := range secFlags {
found := false
for _, flag := range flags {
if flag.GetName() == secFlag.GetName() {
found = true
break
}
}
assert.Truef(t, found, "Expected flag '%s' from Security commands not found in docker flags", secFlag.GetName())
}

// Make sure there are no duplicate flags
flagNames := make(map[string]bool)
for _, flag := range flags {
_, exists := flagNames[flag.GetName()]
assert.Falsef(t, exists, "Duplicate flag '%s' found in docker flags", flag.GetName())
flagNames[flag.GetName()] = true
}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ replace github.com/gfleury/go-bitbucket-v1 => github.com/gfleury/go-bitbucket-v1

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/reshmifrog/jfrog-cli-core/v2 v2.58.5-0.20251110095124-ab9a4102ec5a

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/attiasas/jfrog-cli-core/v2 v2.0.0-20251104113958-abd9de5958c4
// attiasas:convert_flags_public
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/attiasas/jfrog-cli-core/v2 v2.0.0-20251230074913-08e3d39269b0

//replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.54.2-0.20251007084958-5eeaa42c31a6

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/attiasas/jfrog-cli-core/v2 v2.0.0-20251230074913-08e3d39269b0 h1:9Xbjbrh2Rc4ABegZfgHSy7CZG6gc8Hc10tp6yQwWB0Y=
github.com/attiasas/jfrog-cli-core/v2 v2.0.0-20251230074913-08e3d39269b0/go.mod h1:REkU0OfnLYZbQIjD2Cg85DAVP0SRZuV/PxiDfCJiJOc=
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v1.39.5 h1:e/SXuia3rkFtapghJROrydtQpfQaaUgd1cUvyO1mp2w=
Expand Down Expand Up @@ -1218,8 +1220,6 @@ github.com/jfrog/jfrog-cli-application v1.0.2-0.20251210075951-519050602a7f h1:Y
github.com/jfrog/jfrog-cli-application v1.0.2-0.20251210075951-519050602a7f/go.mod h1:xum2HquWO5uExa/A7MQs3TgJJVEeoqTR+6Z4mfBr1Xw=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251230064405-049e011b0bb7 h1:UzFwA39ZTvinCbNvhr9QooeZaF1NBMkxXdBYJwTrXcU=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20251230064405-049e011b0bb7/go.mod h1:T8BzK7jnojx74G/tFs6lTjvNjNO6ltdWaZmY0X0YOOI=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251223102649-e659f6937251 h1:WTyDOaYJUwY6zQujZuL9JQ9Q9+QWj9p31tLb4bJnu4U=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20251223102649-e659f6937251/go.mod h1:REkU0OfnLYZbQIjD2Cg85DAVP0SRZuV/PxiDfCJiJOc=
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0 h1:8S1vE1PeVtrzWkKL0N39cX6XLLNV0It+f6xjRKjw7Ug=
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251204144808-73fa744851c0/go.mod h1:Ijx7tkTp6uDxgmQW+zQKLNztMrz6dcQAoVNXHL7spsU=
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20251205121610-171eb9b0000e h1:0BDeb5lD8qgQMOZJ08E35jUMTlt2Hb0K7Wu0SqO6MrI=
Expand Down
Loading