templating icon indicating copy to clipboard operation
templating copied to clipboard

Support for conditional parameters

Open vlada-shubina opened this issue 3 years ago • 2 comments

Currently all parameters are shown unless hidden via isHidden flag in dotnetcli.host.json. The feature suggests parameters:

  • to be enabled based on condition
  • to be required based on condition

Example:

 "symbols": {
    "username": {
      "type": "parameter",
      "description": "the username to be used for auth",
      "datatype": "text",
      "enabled": "Platform == ios",
      "required": "Platform == ios",
      "replaces": "%USERNAME%",
    }
}

Enabled will allow the option to be suggested as part of tab completion in dotnet new. If Enabled is evaluated to false, and parameter is specified the error occurs. In IDE, Enabled may be represented by enabling/disabling the corresponding control. Required defines if the parameter is required. In case Required is evaluated to "true" but parameter is not specified, the error occurs.

Notes:

  • validation should be implemented to ensure the template doesn't have circular dependencies in conditions.
  • for initial release, likely the symbols in these conditions will be limited to parameters only.
  • keep an eye on performance of evaluating the enabled/required conditions. This should be very simple and very fast.
  • the initial set of variables that should be included for variables are:
    • template symbols of the 'parameter' type
    • more can be added easily later based on user input

This feature partially already suggested here: https://github.com/dotnet/templating/issues/2173, https://github.com/dotnet/templating/issues/4102

vlada-shubina avatar Mar 21 '22 10:03 vlada-shubina

Discuss if we need additional config for visible.

vlada-shubina avatar Mar 21 '22 12:03 vlada-shubina

Subtasks:

  • [x] Documentation: In Progress: https://github.com/dotnet/templating/pull/4876
  • [x] Implementation: In Progress: https://github.com/dotnet/templating/pull/4872
  • [ ] Schemastore update: TBD
  • [ ] Tab completition rich support: TBD

JanKrivanek avatar Jun 28 '22 07:06 JanKrivanek

The work is completed

vlada-shubina avatar Aug 15 '22 16:08 vlada-shubina