Skip to content

Commit

Permalink
(chocolatey#2983) Deprecate --remove option for apikey cmd
Browse files Browse the repository at this point in the history
We plan to replace this option with a proper `remove` subcommand in v2.0
so we are deprecating this now.
  • Loading branch information
vexx32 committed Feb 10, 2023
1 parent 7ae8339 commit 6540a8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class ChocolateyApiKeyCommand : ICommand
{
private readonly IChocolateyConfigSettingsService _configSettingsService;

private const string RemoveOptionDeprecationMessage = @"
The --rem / --remove option is deprecated and will be removed in v2.0.0.
In future versions, this option will be replaced with the `remove` subcommand.
";

public ChocolateyApiKeyCommand(IChocolateyConfigSettingsService configSettingsService)
{
_configSettingsService = configSettingsService;
Expand All @@ -49,7 +54,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"ApiKey - The API key for the source. This is the authentication that identifies you and allows you to push to a source. With some sources this is either a key or it could be a user name and password specified as 'user:password'.",
option => configuration.ApiKeyCommand.Key = option.remove_surrounding_quotes())
.Add("rem|remove",
"Removes an API key from Chocolatey",
"Removes an API key from Chocolatey (DEPRECATED)",
option => configuration.ApiKeyCommand.Remove = true)
;
}
Expand Down Expand Up @@ -82,6 +87,8 @@ source so it doesn't need to be specified every time.
Anything that doesn't contain source and key will list api keys.
");
this.Log().Warn(ChocolateyLoggers.Important, "DEPRECATION NOTICE");
this.Log().Warn(RemoveOptionDeprecationMessage);

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
"chocolatey".Log().Info(@"
Expand Down Expand Up @@ -152,6 +159,8 @@ public virtual void run(ChocolateyConfiguration configuration)
{
if (configuration.ApiKeyCommand.Remove)
{
this.Log().Warn(ChocolateyLoggers.Important, "DEPRECATION NOTICE");
this.Log().Warn(RemoveOptionDeprecationMessage);
_configSettingsService.remove_api_key(configuration);
}
else if (string.IsNullOrWhiteSpace(configuration.ApiKeyCommand.Key))
Expand Down
6 changes: 5 additions & 1 deletion tests/chocolatey-tests/commands/choco-apikey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, ApiKeyCommand {
$Output.Lines | Should -Contain "Removed ApiKey for https://remove.test.com/api"
}

It "Displays a deprecation warning about --rem/--remove" {
$message = "The --rem / --remove option is deprecated and will be removed in v2.0.0."
$Output.Lines | Should -Contain $message -Because "--remove is being deprecated in v2.0.0."
}

# Skipping for now, may need to read the file twice to compare the values
It "Removed apikey do not exist in file" -Skip {
$config = $apiKeys.Where{ $_.source -eq "https://remove.test.com/api" }
$config | Should -BeNullOrEmpty

}
}

Expand Down

0 comments on commit 6540a8f

Please sign in to comment.