choco icon indicating copy to clipboard operation
choco copied to clipboard

(#2500) List parameters in templates

Open TheCakeIsNaOH opened this issue 4 years ago • 1 comments

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:

  1. Install msi.template and zip.template
  2. Make a copy of the msi template folder and rename to "default"
  3. Make a copy of the msi template folder and rename to "non-pkg"
  4. Run choco template --verbose
  5. Check that the parameters are listed correctly
  6. Check that only the msi and zip template folders have the .parameters file

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.

TheCakeIsNaOH avatar Jan 05 '22 22:01 TheCakeIsNaOH

Coverage Status

Coverage remained the same at 28.668% when pulling 565c083abf3954880fa203fee43220b9189f3bfa on TheCakeIsNaOH:template-params into 974a3bce1f8acf29903ac2bbe7d41ae2d6962801 on chocolatey:develop.

coveralls avatar Jun 27 '22 19:06 coveralls

@TheCakeIsNaOH thanks for pulling this together! I am going to go ahead and get this merged in once the CI builds finish.

gep13 avatar Aug 13 '22 21:08 gep13