diff --git a/cmd/dkl-dir2config/assemble.go b/cmd/dkl-dir2config/assemble.go index 0c9f50a..12513fc 100644 --- a/cmd/dkl-dir2config/assemble.go +++ b/cmd/dkl-dir2config/assemble.go @@ -6,6 +6,7 @@ import ( "io" "log" "os" + "os/exec" "strings" "gopkg.in/yaml.v2" @@ -116,9 +117,26 @@ func eachFragment(path string, searchList []FS, walk func(io.Reader) error) (err continue } + genCmd, found := strings.CutPrefix(line, "#!gen ") + if found { + cmdArgs := strings.Fields(genCmd) + if Debug { + log.Print("#!gen ", cmdArgs) + } + + cmd := "gen/" + cmdArgs[0] + args := cmdArgs[1:] + genOutput, err := exec.Command(cmd, args...).Output() + if err != nil { + return fmt.Errorf("gen %v: %w", cmdArgs, err) + } + walk(bytes.NewBuffer(genOutput)) + continue + } + includePath, found := strings.CutPrefix(line, "#!include ") if !found { - continue // or break? + continue } includePath = strings.TrimSpace(includePath) @@ -127,8 +145,7 @@ func eachFragment(path string, searchList []FS, walk func(io.Reader) error) (err } err = eachFragment(includePath, searchList, walk) if err != nil { - err = fmt.Errorf("include %q: %w", includePath, err) - return + return fmt.Errorf("include %q: %w", includePath, err) } }