Skip to content

Commit bf53e56

Browse files
committed
fix: entry override settings file
Signed-off-by: peefy <xpf6677@163.com>
1 parent 322f190 commit bf53e56

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/api/kpm_run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ func RunPkgInPath(opts *opt.CompileOptions) (string, error) {
6969
// CompileWithOpt will compile the kcl program without kcl package.
7070
// Deprecated: This method will not be maintained in the future. Use RunWithOpts instead.
7171
func RunWithOpt(opts *opt.CompileOptions) (*kcl.KCLResultList, error) {
72+
// The entries will override the entries in the settings file.
73+
if opts.HasSettingsYaml() && len(opts.KFilenameList) > 0 && len(opts.Entries()) > 0 {
74+
opts.KFilenameList = []string{}
75+
}
7276
if len(opts.Entries()) > 0 {
7377
for _, entry := range opts.Entries() {
7478
if filepath.IsAbs(entry) {

pkg/api/kpm_run_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ func TestRunWithSettingsOpts(t *testing.T) {
131131
assert.Equal(t, err, nil)
132132
}
133133

134+
func TestRunWithSettingsOptsAndFile(t *testing.T) {
135+
pkgPath := getTestDir("test_settings")
136+
opts := opt.DefaultCompileOptions()
137+
opts.Merge(kcl.WithSettings(filepath.Join(pkgPath, "kcl.yaml")))
138+
opts.SetHasSettingsYaml(true)
139+
opts.SetEntries([]string{filepath.Join(pkgPath, "test.k")})
140+
_, err := RunWithOpt(opts)
141+
assert.Equal(t, err, nil)
142+
}
143+
134144
func TestRunTarPkg(t *testing.T) {
135145
pkgPath := getTestDir("test_run_tar_in_path")
136146
tarPath, _ := filepath.Abs(filepath.Join(pkgPath, "test.tar"))

0 commit comments

Comments
 (0)