Skip to content

Commit

Permalink
(#2761) Allow overriding remembered arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCakeIsNaOH committed Jan 9, 2024
1 parent ecaaf15 commit d23fc36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,16 @@ private static void SetGlobalOptions(IList<string> args, ChocolateyConfiguration
if (timeout > 0 || timeoutString.IsEqualTo("0"))
{
config.CommandExecutionTimeoutSeconds = timeout;
config.CommandExecutionTimeoutSecondsArgumentWasPassed = true;
}
})
.Add("c=|cache=|cachelocation=|cache-location=",
"CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
option => config.CacheLocation = option.UnquoteSafe())
option =>
{
config.CacheLocation = option.UnquoteSafe();
config.CacheLocationArgumentWasPassed = true;
})
.Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
"AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
option => config.AllowUnofficialBuild = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ private void AppendOutput(StringBuilder propertyValues, string append)

// configuration set variables
public string CacheLocation { get; set; }
public bool CacheLocationArgumentWasPassed { get; set; }

public int CommandExecutionTimeoutSeconds { get; set; }
public bool CommandExecutionTimeoutSecondsArgumentWasPassed { get; set; }
public int WebRequestTimeoutSeconds { get; set; }
public string DefaultTemplateName { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,10 +1702,22 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
ConfigurationOptions.OptionSet.Parse(packageArguments);

// there may be overrides from the user running upgrade
if (!string.IsNullOrWhiteSpace(originalConfig.PackageParameters)) config.PackageParameters = originalConfig.PackageParameters;
if (!string.IsNullOrWhiteSpace(originalConfig.InstallArguments)) config.InstallArguments = originalConfig.InstallArguments;
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Username)) config.SourceCommand.Username = originalConfig.SourceCommand.Username;
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Password)) config.SourceCommand.Password = originalConfig.SourceCommand.Password;
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Certificate)) config.SourceCommand.Certificate = originalConfig.SourceCommand.Certificate;
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.CertificatePassword)) config.SourceCommand.CertificatePassword = originalConfig.SourceCommand.CertificatePassword;

if (originalConfig.CacheLocationArgumentWasPassed && !string.IsNullOrWhiteSpace(originalConfig.CacheLocation))
{
config.CacheLocation = originalConfig.CacheLocation;
}

if (originalConfig.CommandExecutionTimeoutSecondsArgumentWasPassed)
{
config.CommandExecutionTimeoutSeconds = originalConfig.CommandExecutionTimeoutSeconds;
}

return originalConfig;
}
Expand Down

0 comments on commit d23fc36

Please sign in to comment.