StephanHCB / go-generator-cli

command line tool to scaffold application code or other files from templates
MIT License
7 stars 5 forks source link

Add support for recursive source -> target generation #17

Open Avataw opened 7 months ago

Avataw commented 7 months ago

It would be great to be able to recursively add a whole folder.

Something like:

  - source: "templates/some_folder/*"
    target: "some_folder"
StephanHCB commented 6 months ago

This is actually already somewhat supported, provided there is a limit to how deep the folder tree goes, and assuming you give your template files a common extension.

  - source: '{{ .file }}'
    target: 'output/{{ .file | replace ".tmpl" "" }}'
    with_files:
      - 'templates/some_folder/*.tmpl'
      - 'templates/some_folder/*/*.tmpl'
      - 'templates/some_folder/*/*/*.tmpl'
      - 'templates/some_folder/*/*/*/*.tmpl'
      - 'templates/some_folder/*/*/*/*/*.tmpl'

Unfortunately, golang package filepath does not support ** in its Glob function, that's why you have to spell out the nesting levels, and it's limited to 4 directory levels I believe.

The feature is mentioned briefly in the readme, look for with_files.

Support for ** would be great, though, so I'll keep this issue open. Will have to go on the lookout for a better Glob function than filepath.Glob.

StephanHCB commented 6 months ago

Or we wait for https://github.com/golang/go/issues/11862 :)