-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGenerateCommand.cs
More file actions
47 lines (39 loc) · 1.94 KB
/
GenerateCommand.cs
File metadata and controls
47 lines (39 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using GoogleMaterialDesignIconsGenerator.Extensions;
using GoogleMaterialDesignIconsGenerator.Model;
using GoogleMaterialDesignIconsGenerator.Service;
using Spectre.Console;
using Spectre.Console.Cli;
namespace GoogleMaterialDesignIconsGenerator;
public sealed class GenerateCommand : AsyncCommand<GenerateCommandSettings>
{
public override async Task<int> ExecuteAsync(CommandContext context, GenerateCommandSettings settings, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(settings);
var iconType = ResolveIconType(settings);
var codeGenerator = new CodeGenerationService();
using var client = new IconHttpClientService();
var metadata = await client.ParseIconsAsync().ConfigureAwait(false);
var filteredIcons = Utility.IconFilter.FilterByFamily(metadata, iconType);
var groupedIcons = Utility.IconFilter.GroupIconsByFamilies(filteredIcons, iconType);
var outputFolder = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, $"../../../../MudBlazor.FontIcons.{iconType.GetDescription()}"));
codeGenerator.GenerateCsFilesUsingRoslyn(iconType, groupedIcons, folder: outputFolder);
if (iconType == IconType.MaterialSymbols)
{
await client.DownloadMaterialSymbolsFontsAsync(Path.Combine(outputFolder, "wwwroot", "font"), cancellationToken).ConfigureAwait(false);
}
return 0;
}
private static IconType ResolveIconType(GenerateCommandSettings settings)
{
if (settings.IconType is { } iconTypeFromOption)
{
return iconTypeFromOption;
}
return AnsiConsole.Prompt(
new SelectionPrompt<IconType>()
.Title("What [green]icon[/] pack to generate?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more options)[/]")
.AddChoices(IconType.MaterialIcons, IconType.MaterialSymbols));
}
}