Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support package_maps config parse and add unit test cases. #167

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading