Skip to content

Commit 16ee99b

Browse files
authored
feat: support package_maps config parse and add unit test cases. (#167)
Signed-off-by: peefy <[email protected]>
1 parent 8448b82 commit 16ee99b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pkg/settings/a_test_unix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ kcl_cli_configs:
1919
- ${KCL_MOD}/file2.k
2020
- ../../base/base.k
2121
disable_none: false
22+
package_maps:
23+
k8s: ../vendor/k8s
2224
`
2325
f, err := LoadFile("./sub/settings.yaml", []byte(s))
2426
if err != nil {
@@ -33,6 +35,8 @@ kcl_cli_configs:
3335
tAssertEQ(t, x.KFilenameList[1], filepath.Join(pwd, "sub", "sub_main.k"))
3436
tAssertEQ(t, x.KFilenameList[2], filepath.Join(pwd, "file2.k"))
3537
tAssertEQ(t, x.KFilenameList[3], filepath.Join(pwd, "..", "base", "base.k"))
38+
tAssertEQ(t, x.ExternalPkgs[1].PkgName, "k8s")
39+
tAssertEQ(t, x.ExternalPkgs[1].PkgPath, "../vendor/k8s")
3640
}
3741

3842
func tAssertEQ(t *testing.T, x, y interface{}) {

pkg/settings/utils_settings_yaml.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ type ConfigStruct struct {
2929
Overrides []string `yaml:"overrides"`
3030
PathSelector []string `yaml:"path_selector"`
3131

32-
StrictRangeCheck bool `yaml:"strict_range_check"`
33-
DisableNone bool `yaml:"disable_none"`
34-
Verbose int `yaml:"verbose"`
35-
Debug bool `yaml:"debug"`
32+
StrictRangeCheck bool `yaml:"strict_range_check"`
33+
DisableNone bool `yaml:"disable_none"`
34+
Verbose int `yaml:"verbose"`
35+
Debug bool `yaml:"debug"`
36+
PackageMaps map[string]string `yaml:"package_maps"`
3637
}
38+
3739
type KeyValueStruct struct {
3840
Key string `yaml:"key"`
3941
Value interface{} `yaml:"value"`
@@ -174,6 +176,15 @@ func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
174176
})
175177
}
176178

179+
// kcl -E k8s=../vendor/k8s
180+
for name, path := range settings.Config.PackageMaps {
181+
externalPkg := gpyrpc.CmdExternalPkgSpec{
182+
PkgName: name,
183+
PkgPath: path,
184+
}
185+
args.ExternalPkgs = append(args.ExternalPkgs, &externalPkg)
186+
}
187+
177188
return args
178189
}
179190

0 commit comments

Comments
 (0)