Closed tobiade closed 2 years ago
This sounds like a reasonable feature, it's just a question of the best way to do the name transformations. I think to keep things simple maybe just a regex delete mode:
For your use case the executing command would be:
p2cli --directory-mode --directory-mode-filename-subst '\.tmpl(\..*)$' '$1'
Which is a bit ugly, but probably avoids edge cases with a properly specified regex. I suspect this sort of option should have a dry-run mode so you can list what the names will come out as for development.
Probably some helpers as well so you can just specify the regex:
p2cli --directory-mode --directory-mode-filename-del '\.tmpl\..*'
One important question here is whether this sort of replacement should also include a selector mode and handle "non-template" files (by copying them unaltered?)
Thanks! I was thinking simple as well - just a simple substring match and replace i.e no need for complicated regex.
Some questions/comments:
.tmpl
)? If so, I'd maybe suggest we take a simple approach and alter their filenames as well. The reason being that the main benefit of this functionality is that it transforms explicitly marked template files to look like non-template files e.g config.tmpl.json
to config.json
by removing the specified template marker. If there's a non-template file that has a template marker, it probably shouldn't have it in the first place, so I'd like to think it'll be safe to remove.
Hi, I have a scenario where I have a directory with template files which have the pattern:
*.tmpl.*
e.gconfig.tmpl.json
. I like naming my files this way to indicate that they are template files which will be rendered during a build.I'm not sure if this a common use-case, but I'd like to be able to rename those files when using
p2cli
withdirectory-mode
enabled.For example, I'd like to remove the
*.tmpl.*
substring in all filenames that have that pattern e.gconfig.tmpl.json
becomesconfig.json
.In short, I'd like to match a pattern in the filename and replace it with a specified string. If you think this is useful, I'm happy to raise a PR for this feature.