-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExportHashesCommand.cs
52 lines (42 loc) · 1.81 KB
/
ExportHashesCommand.cs
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
48
49
50
51
52
using System.Collections.Immutable;
using DotMake.CommandLine;
using Lumina;
using Lumina.Data.Files.Excel;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace EXDTooler;
[CliCommand(Parent = typeof(MainCommand))]
public sealed class ExportHashesCommand
{
public required MainCommand Parent { get; set; }
[CliOption(Required = false, Description = "Path to the game directory. Should be the root of the game's repository.", ValidationRules = CliValidationRules.ExistingDirectory)]
public string? GamePath { get; set; }
[CliOption(Required = false, Description = "Path to the columns file generated by export-columns.", ValidationRules = CliValidationRules.ExistingFile)]
public string? ColumnsFile { get; set; }
[CliOption(Required = false, Description = "Path to the output file.")]
public string? OutputPath { get; set; }
public Task RunAsync()
{
var token = Parent.Init();
var sheets = ColDefReader.FromInputs(GamePath, ColumnsFile);
var schemaSerializer = new SerializerBuilder()
.DisableAliases()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.WithEnumNamingConvention(LowerCaseNamingConvention.Instance)
.WithIndentedSequences()
.Build();
var hashes = sheets.Sheets.Keys
.Select(name => KeyValuePair.Create(name, sheets.GetColumnsHash(name)))
.ToImmutableSortedDictionary();
if (OutputPath != null)
{
using var f = File.OpenWrite(OutputPath);
f.SetLength(0);
using var writer = new StreamWriter(f);
schemaSerializer.Serialize(writer, hashes);
}
else
schemaSerializer.Serialize(Console.Out, hashes);
return Task.CompletedTask;
}
}