Skip to content

Commit

Permalink
(GH-551) Add unset to Config Commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zhao-xu committed Jan 16, 2016
1 parent 3a2217f commit 044d3d5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<options/switches>]
choco config [list]|get|set|unset [<options/switches>]
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Examples");
Expand All @@ -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");
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public enum ConfigCommandType
list,
get,
set,
unset,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 044d3d5

Please sign in to comment.