Skip to content

Commit d23fc36

Browse files
committed
(#2761) Allow overriding remembered arguments
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.
1 parent ecaaf15 commit d23fc36

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,16 @@ private static void SetGlobalOptions(IList<string> args, ChocolateyConfiguration
414414
if (timeout > 0 || timeoutString.IsEqualTo("0"))
415415
{
416416
config.CommandExecutionTimeoutSeconds = timeout;
417+
config.CommandExecutionTimeoutSecondsArgumentWasPassed = true;
417418
}
418419
})
419420
.Add("c=|cache=|cachelocation=|cache-location=",
420421
"CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
421-
option => config.CacheLocation = option.UnquoteSafe())
422+
option =>
423+
{
424+
config.CacheLocation = option.UnquoteSafe();
425+
config.CacheLocationArgumentWasPassed = true;
426+
})
422427
.Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
423428
"AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
424429
option => config.AllowUnofficialBuild = option != null)

src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ private void AppendOutput(StringBuilder propertyValues, string append)
251251

252252
// configuration set variables
253253
public string CacheLocation { get; set; }
254+
public bool CacheLocationArgumentWasPassed { get; set; }
254255

255256
public int CommandExecutionTimeoutSeconds { get; set; }
257+
public bool CommandExecutionTimeoutSecondsArgumentWasPassed { get; set; }
256258
public int WebRequestTimeoutSeconds { get; set; }
257259
public string DefaultTemplateName { get; set; }
258260

src/chocolatey/infrastructure.app/services/NugetService.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,10 +1702,22 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
17021702
ConfigurationOptions.OptionSet.Parse(packageArguments);
17031703

17041704
// there may be overrides from the user running upgrade
1705+
if (!string.IsNullOrWhiteSpace(originalConfig.PackageParameters)) config.PackageParameters = originalConfig.PackageParameters;
1706+
if (!string.IsNullOrWhiteSpace(originalConfig.InstallArguments)) config.InstallArguments = originalConfig.InstallArguments;
17051707
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Username)) config.SourceCommand.Username = originalConfig.SourceCommand.Username;
17061708
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Password)) config.SourceCommand.Password = originalConfig.SourceCommand.Password;
17071709
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Certificate)) config.SourceCommand.Certificate = originalConfig.SourceCommand.Certificate;
17081710
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.CertificatePassword)) config.SourceCommand.CertificatePassword = originalConfig.SourceCommand.CertificatePassword;
1711+
1712+
if (originalConfig.CacheLocationArgumentWasPassed && !string.IsNullOrWhiteSpace(originalConfig.CacheLocation))
1713+
{
1714+
config.CacheLocation = originalConfig.CacheLocation;
1715+
}
1716+
1717+
if (originalConfig.CommandExecutionTimeoutSecondsArgumentWasPassed)
1718+
{
1719+
config.CommandExecutionTimeoutSeconds = originalConfig.CommandExecutionTimeoutSeconds;
1720+
}
17091721

17101722
return originalConfig;
17111723
}

0 commit comments

Comments
 (0)