(#2500) List parameters in templates
Description Of Changes
This adds the ability for the template command to list the parameters in templates. If the template is installed via a package, the parameters get cached in a file called .parameters in the template's directory. This file is ignored by calls to choco new, as it is excluded from being copied.
There another method added to TokenReplacer to get the parameters via regex. This keeps the regex in the TokenReplacer class.
Motivation and Context
It it useful to be able to list the available parameters in a template.
The parameters are cached to reduce the number of files that need to be read to get the parameters. Only templates installed via a .template package have the parameters cached. This is because those cache files would get deleted as a part of the package upgrade process, so any cache files from those templates would be up to date. However, for packages that are installed manually, there is not an efficient way to check that the cache is still valid, so that it why parameters from those templates are always read manually.
Testing
Just like in #2385, unit tests cannot be added yet, due to #2501
Manual testing instructions:
- Install
msi.templateandzip.template - Make a copy of the msi template folder and rename to "default"
- Make a copy of the msi template folder and rename to "non-pkg"
- Run
choco template --verbose - Check that the parameters are listed correctly
- Check that only the msi and zip template folders have the
.parametersfile
Change Types Made
- [ ] Bug fix (non-breaking change)
- [x] Feature / Enhancement (non-breaking change)
- [ ] Breaking change (fix or feature that could cause existing functionality to change)
Related Issue
Fixes #2500 Depends on #2385
Change Checklist
- [ ] Requires a change to the documentation
- [ ] Documentation has been updated
- [ ] Tests to cover my changes, have been added
- [ ] All new and existing tests passed.
- N/A PowerShell v2 compatibility checked.
Coverage remained the same at 28.668% when pulling 565c083abf3954880fa203fee43220b9189f3bfa on TheCakeIsNaOH:template-params into 974a3bce1f8acf29903ac2bbe7d41ae2d6962801 on chocolatey:develop.
@TheCakeIsNaOH thanks for pulling this together! I am going to go ahead and get this merged in once the CI builds finish.