From 044d3d57ff4c972c7d37e8f78894e49776bcc397 Mon Sep 17 00:00:00 2001 From: zhaoxu Date: Fri, 15 Jan 2016 17:14:40 +0800 Subject: [PATCH] (GH-551) Add unset to Config Commands Proxy can be set by 'config set proxy server', but there is no way to turn that off. A new command 'config unset proxy' is created to do the job. --- .../commands/ChocolateyConfigCommandSpecs.cs | 8 ++++++++ .../commands/ChocolateyConfigCommand.cs | 7 ++++++- .../domain/ConfigCommandType.cs | 1 + .../services/ChocolateyConfigSettingsService.cs | 16 ++++++++++++++++ .../services/IChocolateyConfigSettingsService.cs | 1 + 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs index a0b1d63c32..95d4720d46 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 dcc86652b5..0df8bbb141 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 aeb3a5a749..c8f3ba1991 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 6942bdb443..4583cc9700 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 16aa416cd0..3d059ac99d 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); } }