Open grahamehorner opened 5 years ago
Any sort of parameter validation beyond isRequired
would be helpful. In my case, I'd like to validate that the parameter is a file of a particular name, which does exist.
When we move to the System.CommandLine, we will be able to validate on type in the parser.
I think we should have additional validation in the backlog:
Anything else?
Some thoughts I had when the Maui issue was brought up:
“ I think we would also want to do the validation at multiple layers. It would be useful if the core engine would do the validation but also be able to expose the validation rule and the error message so that hosts could pre-validate before passing the parameter to the core engine.”
We need to consider implementing the regex validation in the following layers
dotnet new
CLIThe regex to use can be defined on parameter symbol configuration in template.json.
Some thoughts I had when the Maui issue was brought up:
“ I think we would also want to do the validation at multiple layers. It would be useful if the core engine would do the validation but also be able to expose the validation rule and the error message so that hosts could pre-validate before passing the parameter to the core engine.”
@phenning in case this feature is interested for VS, please let us know here. Once implemented you'll need to implement it in Visual Studio too. It is anticipated that regex for validation should be available via ITemplateInfo
, and exception will be thrown on template creation if parameter value doesn't match the regex, but likely the better UX will be to handle it directly on UI. What do you think?
We'd also need a feature like this (perhaps not just regex, but numeric range bounds, etc) to have a good interactive prompting experience. The prompt loop would want to accept input and validate it before continuing to the next symbol.
I think it's a good idea. Are we thinking for 8.0 template engine, or for a 2/3xx?
A
I assume we'd want the regex pattern to be any valid C# pattern., so we need to validate the expression first before using it to validate the input.
Question: What is the preferred behavior if the regex pattern in the JSON is an invalid regular expression?
@joeloff at packaging/testing time we should log build warnings/errors if an invalid regex is used.
At instantiation-time we should treat it like any other invalid symbol input - it should be a CLI syntax error. We couldn't validate the input because the thing you asked us to validate with is borked.
I assume we'd want the regex pattern to be any valid C# pattern., so we need to validate the expression first before using it to validate the input.
Question: What is the preferred behavior if the regex pattern in the JSON is an invalid regular expression?
@joeloff you can use https://github.com/dotnet/templating/issues/2623 logic to show validation issue during installation or/and instantiation time. I would recommend that in this case it is a warning, and regex validation is just skipped in case of invalid regex.
does the templating engine support validation of parameter values using regex? and/or displaying of error message valid regex is violated?