Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-551) adding unset to config commands #545

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}