feat: add extcode flag

This commit is contained in:
Technofab 2023-03-03 16:53:03 +01:00
parent 629398bcac
commit 894f3a5b2a
No known key found for this signature in database
GPG key ID: A0AA746B951C8830
3 changed files with 19 additions and 2 deletions

View file

@ -11,7 +11,8 @@ import (
)
type Opts struct {
JPath []string
JPath []string
ExtCode map[string]string
}
// Load extracts and transforms the docsonnet data in `filename`, returning the
@ -51,6 +52,10 @@ func Extract(filename string, opts Opts) ([]byte, error) {
// invoke load.libsonnet
vm.ExtCode("main", fmt.Sprintf(`(import "%s")`, filename))
for k, v := range opts.ExtCode {
vm.ExtCode(k, v)
}
data, err := vm.EvaluateAnonymousSnippet("load.libsonnet", string(load))
if err != nil {
return nil, err