Skip to content

Commit 3cc5f34

Browse files
authored
Fix for 'include' flag with spec file (#1503)
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.
1 parent e689762 commit 3cc5f34

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

common/cliutils/spec.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package cliutils
22

33
import (
4+
"strconv"
5+
"strings"
6+
47
speccore "github.com/jfrog/jfrog-cli-core/v2/common/spec"
58
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
69
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
7-
"strconv"
8-
"strings"
910
)
1011

1112
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) {
5859
overrideStringIfSet(&spec.Symlinks, c, "symlinks")
5960
overrideStringIfSet(&spec.Transitive, c, "transitive")
6061
overrideStringIfSet(&spec.PublicGpgKey, c, "gpg-key")
62+
overrideIncludeIfSet(spec, c)
63+
}
64+
65+
// If `include` exist in the cli args, read it to spec.Include as an array split by `;`.
66+
func overrideIncludeIfSet(spec *speccore.File, c *components.Context) {
67+
if c.IsFlagSet("include") {
68+
spec.Include = strings.Split(c.GetStringFlagValue("include"), ";")
69+
}
6170
}
6271

6372
// If `fieldName` exist in the cli args, read it to `field` as a string.

common/spec/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (b *builder) BuildSpec() *SpecFiles {
230230
IncludeDeps: strconv.FormatBool(b.includeDeps),
231231
Symlinks: strconv.FormatBool(b.symlinks),
232232
Transitive: strconv.FormatBool(b.transitive),
233-
include: b.include,
233+
Include: b.include,
234234
},
235235
},
236236
}

common/spec/specfiles.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ type File struct {
9292
Symlinks string
9393
Transitive string
9494
TargetPathInArchive string
95-
include []string
96-
Package string `json:"package,omitempty"`
95+
Include []string `json:"include,omitempty"`
96+
Package string `json:"package,omitempty"`
9797
Version string `json:"version,omitempty"`
9898
Type string `json:"type,omitempty"`
9999
RepoKey string `json:"repoKey,omitempty"`
100100
}
101101

102102
func (f File) GetInclude() []string {
103-
return f.include
103+
return f.Include
104104
}
105105

106106
func (f File) IsFlat(defaultValue bool) (bool, error) {
@@ -188,6 +188,7 @@ func (f *File) ToCommonParams() (*utils.CommonParams, error) {
188188
params.Offset = f.Offset
189189
params.Limit = f.Limit
190190
params.ArchiveEntries = f.ArchiveEntries
191+
params.Include = f.Include
191192
return params, nil
192193
}
193194

plugins/common/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ func OverrideSpecFieldsIfSet(spec *spec.File, c *components.Context) {
6363
OverrideStringIfSet(&spec.Symlinks, c, "symlinks")
6464
OverrideStringIfSet(&spec.Transitive, c, "transitive")
6565
OverrideStringIfSet(&spec.PublicGpgKey, c, "gpg-key")
66+
overrideIncludeIfSet(spec, c)
67+
}
68+
69+
// If `include` exist in the cli args, read it to spec.Include as an array split by `;`.
70+
func overrideIncludeIfSet(spec *spec.File, c *components.Context) {
71+
if c.IsFlagSet("include") {
72+
spec.Include = strings.Split(c.GetStringFlagValue("include"), ";")
73+
}
6674
}

0 commit comments

Comments
 (0)