-
Notifications
You must be signed in to change notification settings - Fork 903
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
(#2377) Add ability to configure default template name #2390
(#2377) Add ability to configure default template name #2390
Conversation
@AdmiringWorm did you have any suggestions about additional Unit Tests that should be added with this PR? |
@TheCakeIsNaOH would be great if you could take a look at this PR as well, and to get your thoughts on it. |
From looking at the changed code, there are two unit tests that at least should be added.
Probably not needed to do a full run for each of those two tests, but would need to assert that the file service is called with the correct values. There are already a few tests for the template service which can be built upon to test those two: https://github.com/chocolatey/choco/blob/develop/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs |
I like the behavior, and the code looks good to me. |
@AdmiringWorm @TheCakeIsNaOH I have moved this away from draft, would both of you be able to take a look, and let me know if you have any comments. Thanks |
cf27684
to
8159a98
Compare
Is it just me, or is IMHO, using
|
8159a98
to
4ecbd3e
Compare
This will be used to allow the user to control which template should be used by default. While it is possible to allow the user to override the default template files, this gives them a little bit more control, to specify via configuration which template they want to use by default.
4ecbd3e
to
7cfc82f
Compare
If the defaultTemplateName configuration value is set, and the user hasn't specified a template name at the command line, check to see whether a template exists with that name. If it does, use this as the template when generating the new package. Given that the default value for the new defaultTemplateName configuration value is an empty string, if the user is directly overriding the default template files folder, this overriding will still take place. Also take into consideration the usage of the --built-in command line option. If this is set, make sure to respect it. The order of precedence is the following: 1. choco new --template=name 2. choco new --built-in 3. choco config defaultTemplateName 4. Manually created files in $env:chocolateyinstall\templates\default 5. Fall back onto the built-in template.
Unit tests have been added to exercise the generate method of the TemplateService to ensure that the template name that is used matches the configured value. - If option is set at the command line, it should win, even if there is a default value in the chocolatey.config file. - If default value is set in chocolatey.config file but path doesn't exist, should use null value - If default value is set in chocolatey.config file and path exists, should be set to this template value - If --built-in option is set, this should override default value in chocolatey.config file
0c0562d
to
fd5b8e9
Compare
@TheCakeIsNaOH thank you for the initial review of this. I have fixed up the suggestion you made and used the order of precedence that you suggested, as this makes sense to me. Going to move forward with getting this merged, and onto some other PR's. |
Description Of Changes
A new configuration value has been added to the chocolatey.config file, name
defaultTemplateName
. This allows the user to specify the name of a template which should be used by default when executing thechoco new
command.Motivation and Context
While it is currently possible to override the files that are used by default when running
choco new
, this requires the user adding the files into a known location. By adding this configuration option, it allows the user to run something like:And then, going forward, anytime that
choco new bob
is run, and new package calledbob
will be created using the zip template.If the user were to run something like the following:
Then the msi template would be used, and the defaultTemplateName would be ignored.
If the user were to override the default template in the required folder, then it will be used when nothing else is set.
However, if the user were to override the default template files in the required folder, and set the defaultTemplateName configuration option, then the latter would win.
Testing
The following things have been done to test this:
choco install zip.template
choco install msi.template
choco new bob
bob
is created, using the standard templatechoco new bob --template-name=zip
bob
is created, using the zip templatechoco config set --name=defaultTemplateName --value=msi
choco new bob
bob
is created, using the msi templatechoco new bob --template-name=zip
bob
is created, using the zip templatechoco config unset --name=defaultTemplateName
C:\ProgramData\chocolatey\templates\msi
toC:\ProgramData\chocolatey\templates\default
choco new bob
bob
is created, using the msi templatechoco new bob --template-name=zip
bob
is created, using the zip templatechoco config set --name=defaultTemplateName --value=zip
choco new bob
bob
is created, using the zip templateChange Types Made
Related Issue
Fixes #2377
Change Checklist