diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs index a0b1d63c3..95d4720d4 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs @@ -131,6 +131,14 @@ public void should_call_service_source_enable_when_command_is_enable() because(); configSettingsService.Verify(c => c.config_set(configuration), Times.Once); } + + [Fact] + public void should_call_service_source_unset_when_command_is_unset() + { + configuration.ConfigCommand.Command = ConfigCommandType.unset; + because(); + configSettingsService.Verify(c => c.config_unset(configuration), Times.Once); + } } } } diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs index dcc86652b..0df8bbb14 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs @@ -96,7 +96,7 @@ Chocolatey will allow you to interact with the configuration file settings. "chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage"); "chocolatey".Log().Info(@" - choco config [list]|get|set [] + choco config [list]|get|set|unset [] "); "chocolatey".Log().Info(ChocolateyLoggers.Important, "Examples"); @@ -107,6 +107,8 @@ choco config get cacheLocation choco config get --name cacheLocation choco config set cacheLocation c:\temp\choco choco config set --name cacheLocation --value c:\temp\choco + choco config unset proxy + choco config unset --name proxy "); "chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches"); @@ -130,6 +132,9 @@ public void run(ChocolateyConfiguration configuration) case ConfigCommandType.set: _configSettingsService.config_set(configuration); break; + case ConfigCommandType.unset: + _configSettingsService.config_unset(configuration); + break; } } diff --git a/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs b/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs index aeb3a5a74..c8f3ba199 100644 --- a/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs +++ b/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs @@ -21,5 +21,6 @@ public enum ConfigCommandType list, get, set, + unset, } } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs index 6942bdb44..4583cc970 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs @@ -356,5 +356,21 @@ public void config_set(ChocolateyConfiguration configuration) } } } + + public void config_unset(ChocolateyConfiguration configuration) + { + var config = config_get(configuration.ConfigCommand.Name); + if (config == null || string.IsNullOrEmpty(config.Value)) + { + this.Log().Warn(NO_CHANGE_MESSAGE); + } + else + { + config.Value = ""; + _xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation); + + this.Log().Warn(() => "Unset {0}".format_with(config.Key)); + } + } } } diff --git a/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs index 16aa416cd..3d059ac99 100644 --- a/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs +++ b/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs @@ -35,5 +35,6 @@ public interface IChocolateyConfigSettingsService void config_list(ChocolateyConfiguration configuration); void config_get(ChocolateyConfiguration configuration); void config_set(ChocolateyConfiguration configuration); + void config_unset(ChocolateyConfiguration configuration); } }