From 0dfaccba76c643ef596e020ebd0486a6d96f74a9 Mon Sep 17 00:00:00 2001 From: agrasth Date: Tue, 2 Dec 2025 12:11:23 +0530 Subject: [PATCH] Fix for 'include' flag with spec file Make Include field public to allow JSON unmarshaling from spec files and direct field access. This is cleaner and more consistent with other fields like Exclusions. --- common/cliutils/spec.go | 13 +++++++++++-- common/spec/builder.go | 2 +- common/spec/specfiles.go | 7 ++++--- plugins/common/config.go | 8 ++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/common/cliutils/spec.go b/common/cliutils/spec.go index 211393f48..ff1079a84 100644 --- a/common/cliutils/spec.go +++ b/common/cliutils/spec.go @@ -1,11 +1,12 @@ package cliutils import ( + "strconv" + "strings" + speccore "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/plugins/components" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" - "strconv" - "strings" ) func GetSpec(c *components.Context, isDownload, overrideFieldsIfSet bool) (specFiles *speccore.SpecFiles, err error) { @@ -58,6 +59,14 @@ func OverrideFieldsIfSet(spec *speccore.File, c *components.Context) { overrideStringIfSet(&spec.Symlinks, c, "symlinks") overrideStringIfSet(&spec.Transitive, c, "transitive") overrideStringIfSet(&spec.PublicGpgKey, c, "gpg-key") + overrideIncludeIfSet(spec, c) +} + +// If `include` exist in the cli args, read it to spec.Include as an array split by `;`. +func overrideIncludeIfSet(spec *speccore.File, c *components.Context) { + if c.IsFlagSet("include") { + spec.Include = strings.Split(c.GetStringFlagValue("include"), ";") + } } // If `fieldName` exist in the cli args, read it to `field` as a string. diff --git a/common/spec/builder.go b/common/spec/builder.go index 38291635c..5157570fe 100644 --- a/common/spec/builder.go +++ b/common/spec/builder.go @@ -230,7 +230,7 @@ func (b *builder) BuildSpec() *SpecFiles { IncludeDeps: strconv.FormatBool(b.includeDeps), Symlinks: strconv.FormatBool(b.symlinks), Transitive: strconv.FormatBool(b.transitive), - include: b.include, + Include: b.include, }, }, } diff --git a/common/spec/specfiles.go b/common/spec/specfiles.go index 21efc8e3a..2ff7e30cb 100644 --- a/common/spec/specfiles.go +++ b/common/spec/specfiles.go @@ -92,15 +92,15 @@ type File struct { Symlinks string Transitive string TargetPathInArchive string - include []string - Package string `json:"package,omitempty"` + Include []string `json:"include,omitempty"` + Package string `json:"package,omitempty"` Version string `json:"version,omitempty"` Type string `json:"type,omitempty"` RepoKey string `json:"repoKey,omitempty"` } func (f File) GetInclude() []string { - return f.include + return f.Include } func (f File) IsFlat(defaultValue bool) (bool, error) { @@ -188,6 +188,7 @@ func (f *File) ToCommonParams() (*utils.CommonParams, error) { params.Offset = f.Offset params.Limit = f.Limit params.ArchiveEntries = f.ArchiveEntries + params.Include = f.Include return params, nil } diff --git a/plugins/common/config.go b/plugins/common/config.go index a906321ab..077fe68eb 100644 --- a/plugins/common/config.go +++ b/plugins/common/config.go @@ -63,4 +63,12 @@ func OverrideSpecFieldsIfSet(spec *spec.File, c *components.Context) { OverrideStringIfSet(&spec.Symlinks, c, "symlinks") OverrideStringIfSet(&spec.Transitive, c, "transitive") OverrideStringIfSet(&spec.PublicGpgKey, c, "gpg-key") + overrideIncludeIfSet(spec, c) +} + +// If `include` exist in the cli args, read it to spec.Include as an array split by `;`. +func overrideIncludeIfSet(spec *spec.File, c *components.Context) { + if c.IsFlagSet("include") { + spec.Include = strings.Split(c.GetStringFlagValue("include"), ";") + } }