Skip to content

Commit

Permalink
feat: support package_maps config parse and add unit test cases.
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Oct 23, 2023
1 parent 8448b82 commit 20ae4ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/settings/a_test_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ kcl_cli_configs:
- ${KCL_MOD}/file2.k
- ../../base/base.k
disable_none: false
package_maps:
k8s: ../vendor/k8s
`
f, err := LoadFile("./sub/settings.yaml", []byte(s))
if err != nil {
Expand All @@ -33,6 +35,8 @@ kcl_cli_configs:
tAssertEQ(t, x.KFilenameList[1], filepath.Join(pwd, "sub", "sub_main.k"))
tAssertEQ(t, x.KFilenameList[2], filepath.Join(pwd, "file2.k"))
tAssertEQ(t, x.KFilenameList[3], filepath.Join(pwd, "..", "base", "base.k"))
tAssertEQ(t, x.ExternalPkgs[1].PkgName, "k8s")
tAssertEQ(t, x.ExternalPkgs[1].PkgPath, "../vendor/k8s")
}

func tAssertEQ(t *testing.T, x, y interface{}) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/settings/a_test_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ kcl_cli_configs:
- ${KCL_MOD}/file2.k
- ../../base/base.k
disable_none: false
package_maps:
k8s: ..\\vendor\\k8s
`
f, err := LoadFile("./sub/settings.yaml", []byte(s))
if err != nil {
Expand All @@ -30,6 +32,8 @@ kcl_cli_configs:
tAssertEQ(t, x.KFilenameList[1], filepath.Join(pwd, "sub", "sub_main.k"))
tAssertEQ(t, x.KFilenameList[2], filepath.Join(pwd, "file2.k"))
tAssertEQ(t, x.KFilenameList[3], filepath.Join(pwd, "..", "base", "base.k"))
tAssertEQ(t, x.ExternalPkgs[1].PkgName, "k8s")
tAssertEQ(t, x.ExternalPkgs[1].PkgPath, filepath.Join(pwd, "..", "vendor", "k8s"))
}

func tAssertEQ(t *testing.T, x, y interface{}) {
Expand Down
19 changes: 15 additions & 4 deletions pkg/settings/utils_settings_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ type ConfigStruct struct {
Overrides []string `yaml:"overrides"`
PathSelector []string `yaml:"path_selector"`

StrictRangeCheck bool `yaml:"strict_range_check"`
DisableNone bool `yaml:"disable_none"`
Verbose int `yaml:"verbose"`
Debug bool `yaml:"debug"`
StrictRangeCheck bool `yaml:"strict_range_check"`
DisableNone bool `yaml:"disable_none"`
Verbose int `yaml:"verbose"`
Debug bool `yaml:"debug"`
PackageMaps map[string]string `yaml:"package_maps"`
}

type KeyValueStruct struct {
Key string `yaml:"key"`
Value interface{} `yaml:"value"`
Expand Down Expand Up @@ -174,6 +176,15 @@ func (settings *SettingsFile) To_ExecProgram_Args() *gpyrpc.ExecProgram_Args {
})
}

// kcl -E k8s=../vendor/k8s
for name, path := range settings.Config.PackageMaps {
externalPkg := gpyrpc.CmdExternalPkgSpec{
PkgName: name,
PkgPath: path,
}
args.ExternalPkgs = append(args.ExternalPkgs, &externalPkg)
}

return args
}

Expand Down

0 comments on commit 20ae4ee

Please sign in to comment.