2025-02-24 22:53:55 -06:00
|
|
|
namespace AltGen.Console.Config;
|
|
|
|
|
|
2025-03-08 19:31:56 -06:00
|
|
|
sealed class RemoveConfigCommand(
|
2025-03-14 22:02:22 -05:00
|
|
|
IAnsiConsole console,
|
|
|
|
|
IAppSettingsManager settingsManager
|
2025-03-08 19:31:56 -06:00
|
|
|
) : AsyncCommand<RemoveConfigCommand.Settings>
|
2025-02-24 22:53:55 -06:00
|
|
|
{
|
2025-03-08 19:31:56 -06:00
|
|
|
readonly IAnsiConsole _console = console;
|
2025-03-14 22:02:22 -05:00
|
|
|
readonly IAppSettingsManager _settingsManager = settingsManager;
|
2025-03-08 19:31:56 -06:00
|
|
|
|
2025-03-14 22:02:22 -05:00
|
|
|
public class Settings : CommandSettings
|
2025-02-24 22:53:55 -06:00
|
|
|
{
|
|
|
|
|
[CommandArgument(1, "<provider>")]
|
|
|
|
|
[Description("The provider to remove.")]
|
|
|
|
|
public string Provider { get; init; } = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
|
|
|
|
|
{
|
2025-03-14 22:02:22 -05:00
|
|
|
if (_settingsManager.AppSettingsExist() is false)
|
2025-03-08 19:31:56 -06:00
|
|
|
{
|
2025-03-09 12:49:28 -05:00
|
|
|
throw new ConfigException("No existing settings found.");
|
2025-03-08 19:31:56 -06:00
|
|
|
}
|
|
|
|
|
|
2025-03-14 22:02:22 -05:00
|
|
|
var appSettings = await _settingsManager.GetAppSettingsAsync();
|
2025-03-08 19:31:56 -06:00
|
|
|
var updatedAppSettings = appSettings.RemoveProvider(settings);
|
2025-03-14 22:02:22 -05:00
|
|
|
await _settingsManager.SaveAppSettingsAsync(updatedAppSettings);
|
2025-03-08 19:31:56 -06:00
|
|
|
_console.MarkupLine($"[bold]{settings.Provider}[/] has been removed.");
|
2025-02-24 22:53:55 -06:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|