Switched Generation command to use lambda handler.

This commit is contained in:
Harrison Deng 2022-05-18 22:03:08 -05:00
parent be2cf466b4
commit 1cb6730bb1

View File

@ -14,17 +14,13 @@ namespace DotNetResxUtils.Commands
public GenerationCommand() : base(NAME, DESC) public GenerationCommand() : base(NAME, DESC)
{ {
Argument<FileInfo> destArg = new Argument<FileInfo>("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated.");
Add(destArg);
Option<FileInfo?> fromOpt = new Option<FileInfo?>("--from", "Generates a .resx file from the given file."); Option<FileInfo?> fromOpt = new Option<FileInfo?>("--from", "Generates a .resx file from the given file.");
Add(fromOpt);
Argument<FileInfo> destArg = new Argument<FileInfo>("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated."); this.SetHandler(async (FileInfo to, FileInfo? from) =>
this.AddOption(fromOpt);
this.AddArgument(destArg);
this.SetHandler<FileInfo, FileInfo?>(CommandHandler, destArg, fromOpt);
}
private async void CommandHandler(FileInfo to, FileInfo? from)
{ {
IDictionary<string, string> flattened = new Dictionary<string, string>(); IDictionary<string, string> flattened = new Dictionary<string, string>();
if (from != null) if (from != null)
@ -38,6 +34,7 @@ namespace DotNetResxUtils.Commands
resxWriter.AddResource(keyVal.Key, keyVal.Value); resxWriter.AddResource(keyVal.Key, keyVal.Value);
} }
} }
}, destArg, fromOpt);
} }
private async Task<IDictionary<string, string>> FlattenJson(FileInfo jsonFile) private async Task<IDictionary<string, string>> FlattenJson(FileInfo jsonFile)