diff --git a/pkg/native/api.go b/pkg/native/api.go index ff89c917..6f358399 100644 --- a/pkg/native/api.go +++ b/pkg/native/api.go @@ -20,6 +20,19 @@ func Run(path string, opts ...kcl.Option) (*kcl.KCLResultList, error) { return run([]string{path}, opts...) } +func MustRunPaths(paths []string, opts ...kcl.Option) *kcl.KCLResultList { + v, err := RunPaths(paths, opts...) + if err != nil { + panic(err) + } + + return v +} + +func RunPaths(paths []string, opts ...kcl.Option) (*kcl.KCLResultList, error) { + return run(paths, opts...) +} + func run(pathList []string, opts ...kcl.Option) (*kcl.KCLResultList, error) { args, err := kcl.ParseArgs(pathList, opts...) if err != nil { diff --git a/pkg/native/api_test.go b/pkg/native/api_test.go index 41b353aa..aaa7d423 100644 --- a/pkg/native/api_test.go +++ b/pkg/native/api_test.go @@ -26,6 +26,15 @@ func TestNativeRun(t *testing.T) { fmt.Println(yaml) } +func ExampleNativeRunPaths() { + yaml := MustRunPaths([]string{"testdata/1.k", "testdata/2.k"}).GetRawYamlResult() + fmt.Println(yaml) + + // output: + // a: b + // c: d +} + func TestNativeRunWithPlugin(t *testing.T) { plugin.RegisterPlugin(plugin.Plugin{ Name: "my_plugin", diff --git a/pkg/native/testdata/1.k b/pkg/native/testdata/1.k new file mode 100644 index 00000000..d4183879 --- /dev/null +++ b/pkg/native/testdata/1.k @@ -0,0 +1 @@ +a = "b" diff --git a/pkg/native/testdata/2.k b/pkg/native/testdata/2.k new file mode 100644 index 00000000..3d0c5e61 --- /dev/null +++ b/pkg/native/testdata/2.k @@ -0,0 +1 @@ +c = "d"