Skip to content

Commit

Permalink
(chocolatey#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 authored and gep13 committed Sep 22, 2024
1 parent 86c257e commit 64cd3bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,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 @@ -254,8 +254,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
20 changes: 20 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,16 @@ 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;
Expand All @@ -1939,6 +1949,16 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
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 64cd3bf

Please sign in to comment.