Replies: 2 comments
-
This is not supported right now, but it would be nice indeed. Track progress in #398. Only validation we have now is type-casting the answer. |
Beta Was this translation helpful? Give feedback.
-
EDIT: I leave it here because you can get some inspiration from it, but the following won't be able to validate an answer right after it was given. It might still be possible to validate the answer once they were all given, in a context hook, or in a task. There's probably more hackery we could do to alter/validate the Jinja context that is passed again and again when prompting the user though. It's probably possible to add a import re
from jinja2.ext import Extension
class ValidateAgainstRegex(Extension):
def __init__(self, environment):
super().__init__(environment)
environment.filters["validate"] = validate
def validate(s, pattern):
if not re.match(s, pattern):
raise ValueError("answer does not match regex")
return s _jinja_extensions:
- your_pulished_package.ValidateAgainstRegex You don't even have to actually publish a package, you can use https://github.com/pawamoy/copier-templates-extensions instead, to put your extension directly into your template repository. |
Beta Was this translation helpful? Give feedback.
-
Is there a means to check the answers?
Use Cases:
If not maybe a workaround? I was thinking of using a when check, but would still need to exit()
Beta Was this translation helpful? Give feedback.
All reactions