Skip to content

Commit 6869f56

Browse files
committed
Fix for 'include' flag with spec file
1 parent e689762 commit 6869f56

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

common/cliutils/spec.go

Lines changed: 12 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,15 @@ 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+
include := strings.Split(c.GetStringFlagValue("include"), ";")
69+
spec.SetInclude(include)
70+
}
6171
}
6272

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

common/project/projectconfig.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,26 @@ func ReadResolutionOnlyConfiguration(confFilePath string) (*RepositoryConfig, er
247247
}
248248
return GetRepoConfigByPrefix(confFilePath, ProjectConfigResolverPrefix, vConfig)
249249
}
250+
251+
// GetDeploymentConfiguration reads the deployment configuration from the project config file
252+
func GetDeploymentConfiguration(projectType ProjectType) (*RepositoryConfig, error) {
253+
// Get configuration file path.
254+
confFilePath, exists, err := GetProjectConfFilePath(projectType)
255+
if err != nil {
256+
return nil, err
257+
}
258+
if !exists {
259+
return nil, errorutils.CheckErrorf("%s Project configuration does not exist.", projectType.String())
260+
}
261+
return ReadDeploymentConfiguration(confFilePath)
262+
}
263+
264+
// ReadDeploymentConfiguration reads the deployer section from the config file
265+
func ReadDeploymentConfiguration(confFilePath string) (*RepositoryConfig, error) {
266+
log.Debug("Preparing to read the deployment config file", confFilePath)
267+
vConfig, err := ReadConfigFile(confFilePath, YAML)
268+
if err != nil {
269+
return nil, err
270+
}
271+
return GetRepoConfigByPrefix(confFilePath, ProjectConfigDeployerPrefix, vConfig)
272+
}

common/spec/specfiles.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func (f File) GetInclude() []string {
103103
return f.include
104104
}
105105

106+
func (f *File) SetInclude(include []string) {
107+
f.include = include
108+
}
109+
106110
func (f File) IsFlat(defaultValue bool) (bool, error) {
107111
return clientutils.StringToBool(f.Flat, defaultValue)
108112
}

plugins/common/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@ 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+
include := strings.Split(c.GetStringFlagValue("include"), ";")
73+
spec.SetInclude(include)
74+
}
6675
}

0 commit comments

Comments
 (0)