-
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
(#2503) Add ability to export saved arguments #2506
base: develop
Are you sure you want to change the base?
(#2503) Add ability to export saved arguments #2506
Conversation
d2c4fc9
to
dac10e7
Compare
I'm open to suggestions on more unit tests that should be added, and if the |
6333235
to
265ec90
Compare
265ec90
to
ace284f
Compare
ace284f
to
6dfe263
Compare
6dfe263
to
b7b4012
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed a couple things on this one. Let me know if you have any questions about my comments.
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
Outdated
Show resolved
Hide resolved
|
||
//Mirrors the arguments captured in ChocolateyPackageService.capture_arguments() | ||
|
||
if (configuration.Prerelease) xw.WriteAttributeString("prerelease", "true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings, for example prerelease
are starting to feel a little bit like "magic" strings, as they are being used in multiple places as bare strings. Being used here, as well as when naming the attributes in the PackagesConfigFilePackageSetting
class. Should we break these out into a new class, of const string's, or similar, so we can define them once, and use in multiple places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why not use the PackagesConfigFilePackageSetting
(or PackagesConfigFileSetting
) class to do the xml serialization, that way the strings would be in only one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that is not a bad idea. That would mean that the serialized XML could be used elsewhere. Although, I don't immediately see a need for it anywhere else, but putting it in one of these classes would mean that we "simplify" the command class, and do the work elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've switched to serializing that class to create the xml. It required adding members so the boolean options are not serialized if they are not specified, but otherwise I like the implementation.
src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs
Show resolved
Hide resolved
b7b4012
to
ee96706
Compare
Converted to draft, as I found some inconsistent behavior with some arguments not being included, will do some debugging. |
2840467
to
eb3fe6b
Compare
I've fixed the inconsistent behavior I think, and updated the manual testing. This is ready for a re-review. |
1e9c0d1
to
097f703
Compare
1438bc6
to
0b51a7d
Compare
This is draft until #3003 is merged/closed, as the implementation of this depends on what happens with that PR. |
Need to discuss what would happen here with regard to sensitive arguments that might have been passed in with Chocolatey Licensed Extension, i.e. --package-parameters-sensitive. We can't allow those to be included in the exported file. |
Given that each item has to have support manually typed in, that is not a concern, at least not in the open source code base, as the open source code base does not support |
0b51a7d
to
25541d9
Compare
I've rebased this to depend on #3003 |
@TheCakeIsNaOH thanks for the work. Makes it easier to export my current package config |
This helps ensure that package IDs are handled in a case insensitive manner.
This allows overriding of remembered package parameters, install arguments, cache location and execution timeout during upgrade. So a user can pass in different package parameters or arguments without having to completely reinstall the package or turn off remembered arguments. Switch arguments cannot be checked, because the lack of a switch normally would mean that they are just relying on the remembered args to remember it, so there is no way to determine if an override of the remembered args is appropriate.
…ration This adds a new method, GetPackageConfigFromRememberedArguments which is similar to SetConfigFromRememberedArguments, but operates using a different method. First, a OptionSet is set up, so only the config that is passed in is modified, instead of the config that the global options parser was set with with. Second, it returns the modified configuration instead of the original configuration, because it is the local configuration being modified. Third, it has a more general name and changes log messages to be more general, so it later can more easily be reused for uninstall and export. This change fixes remembered arguments when Chocolatey is used as a library, like in ChocolateyGUI, where the config that is passed to the install_run method is not necessarily the same config object that was used to set up the global argument parser. The downside of using a new commandline parser is that it opens up the possibility of drift between the upgrade/global arguments and this added parser. However, this is not an issue because the format of the saved arguments is known, and any added arguments there would not work without being added here as well, which would be picked up during development.
Instead of exporting via building an xml document manually, this creates a PackagesConfigFilePackageSetting and serializes that to create the xml document that is saved. This allows for usage of the same class as is used to read in packages.config files to export those files. The reason the various "Specified" members are added to the PackagesConfigFilePackageSetting class is so if an element is not set during export, it will not show up at all in the resulting serialized packages.config file.
This adds the --include-remembered-arguments option which is used to export any remembered arguments. It reuses the GetPackageConfigFromRememberedArguments method in the NugetService to read and parse the remembered arguments.
25541d9
to
db7ea32
Compare
Description Of Changes
This adds the --include-remembered-arguments option which is used to
export any remembered arguments. This reuses the
set_package_config_for_upgrade method in the NugetService to read and
parse the saved arguments.
Changes the set_package_config_for_upgrade method in the nuget service
to be public so it can be accessed for purposes of parsing the saved
arguments so they can be exported.
Motivation and Context
This is rounding out the feature set of the export command, so it is able to export the saved arguments.
Testing
.\choco.exe install iperf2 --allow-unofficial --pre --ignore-dependencies --forcex86 --ia="/test" --override-arguments --params="/test" --args-global --params-global -m --allow-downgrade --timeout=0 --fail-on-stderr --use-system-powershell
.\choco.exe install wget --allow-unofficial
.\choco.exe install z3 --package-parameters="'/z3param'" --forcex86
choco export --allow-unofficial --include-remembered-arguments
packages.config
file and check that it is something like this:This validates that the remembered argument are export correctly, that they are not reused between packages, and that they can be set again in a later package.
Change Types Made
Related Issue
Fixes #2503
Depends on/based on #3003
Change Checklist