Skip to content

Commit dc243a8

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 45cd1a4 commit dc243a8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,16 @@ private static void SetGlobalOptions(IList<string> args, ChocolateyConfiguration
420420
if (timeout > 0 || timeoutString.IsEqualTo("0"))
421421
{
422422
config.CommandExecutionTimeoutSeconds = timeout;
423+
config.CommandExecutionTimeoutSecondsArgumentWasPassed = true;
423424
}
424425
})
425426
.Add("c=|cache=|cachelocation=|cache-location=",
426427
"CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
427-
option => config.CacheLocation = option.UnquoteSafe())
428+
option =>
429+
{
430+
config.CacheLocation = option.UnquoteSafe();
431+
config.CacheLocationArgumentWasPassed = true;
432+
})
428433
.Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
429434
"AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
430435
option => config.AllowUnofficialBuild = option != null)

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

+2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ private void AppendOutput(StringBuilder propertyValues, string append)
252252

253253
// configuration set variables
254254
public string CacheLocation { get; set; }
255+
public bool CacheLocationArgumentWasPassed { get; set; }
255256

256257
public int CommandExecutionTimeoutSeconds { get; set; }
258+
public bool CommandExecutionTimeoutSecondsArgumentWasPassed { get; set; }
257259
public int WebRequestTimeoutSeconds { get; set; }
258260
public string DefaultTemplateName { get; set; }
259261

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

+20
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,16 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
19681968
ConfigurationOptions.OptionSet.Parse(packageArguments);
19691969

19701970
// there may be overrides from the user running upgrade
1971+
if (!string.IsNullOrWhiteSpace(originalConfig.PackageParameters))
1972+
{
1973+
config.PackageParameters = originalConfig.PackageParameters;
1974+
}
1975+
1976+
if (!string.IsNullOrWhiteSpace(originalConfig.InstallArguments))
1977+
{
1978+
config.InstallArguments = originalConfig.InstallArguments;
1979+
}
1980+
19711981
if (!string.IsNullOrWhiteSpace(originalConfig.SourceCommand.Username))
19721982
{
19731983
config.SourceCommand.Username = originalConfig.SourceCommand.Username;
@@ -1988,6 +1998,16 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
19881998
config.SourceCommand.CertificatePassword = originalConfig.SourceCommand.CertificatePassword;
19891999
}
19902000

2001+
if (originalConfig.CacheLocationArgumentWasPassed && !string.IsNullOrWhiteSpace(originalConfig.CacheLocation))
2002+
{
2003+
config.CacheLocation = originalConfig.CacheLocation;
2004+
}
2005+
2006+
if (originalConfig.CommandExecutionTimeoutSecondsArgumentWasPassed)
2007+
{
2008+
config.CommandExecutionTimeoutSeconds = originalConfig.CommandExecutionTimeoutSeconds;
2009+
}
2010+
19912011
return originalConfig;
19922012
}
19932013

0 commit comments

Comments
 (0)