Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating parameter using RegExp #2038

Open
grahamehorner opened this issue Jul 31, 2019 · 9 comments
Open

Validating parameter using RegExp #2038

grahamehorner opened this issue Jul 31, 2019 · 9 comments
Assignees
Labels
area: CLI Related to dotnet new CLI (usually dotnet/TemplateEngine.CLI source code) feature The issue defines new feature. good first issue easy issue, good for first-time contribution to the repo Priority:2 Work that is important, but not critical for the release triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Milestone

Comments

@grahamehorner
Copy link

does the templating engine support validation of parameter values using regex? and/or displaying of error message valid regex is violated?

@grahamehorner grahamehorner changed the title Q: parameter regexp Q: validating parameter using regexp Jul 31, 2019
@donJoseLuis donJoseLuis added need-discussion Requires internal discussion prior to answering in an issue. triaged The issue was evaluated by the triage team, placed on correct area, next action defined. labels Mar 20, 2020
@nickwesselman
Copy link

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.

@vlada-shubina vlada-shubina added need-pm-discussion Need agreement from PM that the issue aligns to targeted stories for any of the next 2 releases and removed need-discussion Requires internal discussion prior to answering in an issue. labels Sep 14, 2020
@vlada-shubina vlada-shubina removed the triaged The issue was evaluated by the triage team, placed on correct area, next action defined. label Apr 13, 2021
@KathleenDollard
Copy link

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:

  • RegEx (probably)
  • Min/Max range

Anything else?

@KathleenDollard KathleenDollard removed the need-pm-discussion Need agreement from PM that the issue aligns to targeted stories for any of the next 2 releases label Apr 13, 2021
@bekir-ozturk bekir-ozturk added this to the Backlog milestone Apr 19, 2021
@bekir-ozturk bekir-ozturk added triaged The issue was evaluated by the triage team, placed on correct area, next action defined. User Story A single user-facing feature. Can be grouped under an epic. Epic Groups multiple user stories. Can be grouped under a theme. labels Apr 19, 2021
@vlada-shubina vlada-shubina removed the Epic Groups multiple user stories. Can be grouped under a theme. label Jul 1, 2021
@vlada-shubina vlada-shubina changed the title Q: validating parameter using regexp [Epic] validating parameter using regexp Jul 27, 2021
@donJoseLuis donJoseLuis removed the User Story A single user-facing feature. Can be grouped under an epic. label Jan 5, 2023
@donJoseLuis donJoseLuis changed the title [Epic] validating parameter using regexp Validating parameter using RegExp Jan 5, 2023
@phenning
Copy link
Contributor

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.”

@YuliiaKovalova YuliiaKovalova added Priority:2 Work that is important, but not critical for the release good first issue easy issue, good for first-time contribution to the repo area: CLI Related to dotnet new CLI (usually dotnet/TemplateEngine.CLI source code) feature The issue defines new feature. labels May 16, 2023
@vlada-shubina
Copy link
Member

We need to consider implementing the regex validation in the following layers

  • dotnet new CLI
  • handling passed parameters in Edge (for a generic case)

The 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?

@baronfel
Copy link
Member

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.

@phenning
Copy link
Contributor

I think it's a good idea. Are we thinking for 8.0 template engine, or for a 2/3xx?

A

@joeloff
Copy link
Member

joeloff commented Jul 5, 2023

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?

@baronfel
Copy link
Member

baronfel commented Jul 5, 2023

@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.

@vlada-shubina
Copy link
Member

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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CLI Related to dotnet new CLI (usually dotnet/TemplateEngine.CLI source code) feature The issue defines new feature. good first issue easy issue, good for first-time contribution to the repo Priority:2 Work that is important, but not critical for the release triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

10 participants