Skip to content

Commit

Permalink
(chocolatey#1479) Rework set package config method
Browse files Browse the repository at this point in the history
This brings out the functionality from the
set_package_config_for_upgrade method to a more generic name, and adds
in another parameter to prepare for setting remembered args for
uninstall as well as upgrade. It also updates the logging and comments
to make them generic for both upgrades and uninstalls.

An alias/forwarding method is added for backwards compatibility.
  • Loading branch information
TheCakeIsNaOH committed Apr 28, 2024
1 parent 85ab916 commit 1f484ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/chocolatey/infrastructure.app/services/INugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ public interface INugetService : ISourceRunner
/// </summary>
/// <param name="config">The original configuration.</param>
/// <param name="packageInfo">The package information.</param>
/// <param name="commandType">The command type</param>
/// <returns>The modified configuration, so it can be used</returns>
ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config,
ChocolateyPackageInformation packageInfo);
ChocolateyPackageInformation packageInfo, CommandNameType commandType = CommandNameType.Upgrade);

#pragma warning disable IDE0022, IDE1006
[Obsolete("This overload is deprecated and will be removed in v3.")]
Expand Down
15 changes: 9 additions & 6 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,10 @@ public virtual ConcurrentDictionary<string, PackageResult> GetOutdated(Chocolate
}

[Obsolete("This method is deprecated and will be removed in v3.")]
protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo)
protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo, CommandNameType commandType = CommandNameType.Upgrade)
{
if (!config.Features.UseRememberedArgumentsForUpgrades || string.IsNullOrWhiteSpace(packageInfo.Arguments))
if ((commandType == CommandNameType.Upgrade && !config.Features.UseRememberedArgumentsForUpgrades) ||
(commandType == CommandNameType.Uninstall && !config.Features.UseRememberedArgumentsForUninstalls) || string.IsNullOrWhiteSpace(packageInfo.Arguments))
{
return config;
}
Expand All @@ -1794,7 +1795,7 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
if (!ArgumentsUtility.SensitiveArgumentsProvided(packageArgumentsUnencrypted))
{
sensitiveArgs = false;
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments for upgrade: {1}".FormatWith(packageInfo.Package.Id, packageArgumentsUnencrypted.EscapeCurlyBraces()));
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments: {1}".FormatWith(packageInfo.Package.Id, packageArgumentsUnencrypted.EscapeCurlyBraces()));
}

var packageArgumentsSplit = packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -1815,7 +1816,7 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco

if (sensitiveArgs)
{
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to upgrade arguments. Values not shown due to detected sensitive arguments".FormatWith(packageInfo.Package.Id, optionName.EscapeCurlyBraces()));
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to arguments. Values not shown due to detected sensitive arguments".FormatWith(packageInfo.Package.Id, optionName.EscapeCurlyBraces()));
}
packageArguments.Add("--{0}{1}".FormatWith(optionName, string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue));
}
Expand Down Expand Up @@ -1873,10 +1874,12 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
/// </summary>
/// <param name="config">The original configuration.</param>
/// <param name="packageInfo">The package information.</param>
/// <param name="commandType">The command type</param>
/// <returns>The modified configuration, so it can be used</returns>
public virtual ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo)
public virtual ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo, CommandNameType commandType = CommandNameType.Upgrade)
{
if (!config.Features.UseRememberedArgumentsForUpgrades || string.IsNullOrWhiteSpace(packageInfo.Arguments))
if ((commandType == CommandNameType.Upgrade && !config.Features.UseRememberedArgumentsForUpgrades) ||
(commandType == CommandNameType.Uninstall && !config.Features.UseRememberedArgumentsForUninstalls) || string.IsNullOrWhiteSpace(packageInfo.Arguments))
{
return config;
}
Expand Down

0 comments on commit 1f484ed

Please sign in to comment.