diff --git a/DotNetResxUtils/Commands/GenerationCommand.cs b/DotNetResxUtils/Commands/GenerationCommand.cs index 0ddec8f..69034c6 100644 --- a/DotNetResxUtils/Commands/GenerationCommand.cs +++ b/DotNetResxUtils/Commands/GenerationCommand.cs @@ -7,37 +7,34 @@ using System.Resources.NetStandard; namespace DotNetResxUtils.Commands { - internal class GenerationCommand : Command + internal class GenerationCommand : Command { const string NAME = "generate"; const string DESC = "Generate a .resx file."; public GenerationCommand() : base(NAME, DESC) { + Argument destArg = new Argument("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated."); + Add(destArg); Option fromOpt = new Option("--from", "Generates a .resx file from the given file."); + Add(fromOpt); - Argument destArg = new Argument("destination", "The destination path to store this file. If no extension is given, .resx will automatically be concatenated."); - - this.AddOption(fromOpt); - this.AddArgument(destArg); - - this.SetHandler(CommandHandler, destArg, fromOpt); - } - private async void CommandHandler(FileInfo to, FileInfo? from) - { - IDictionary flattened = new Dictionary(); - if (from != null) + this.SetHandler(async (FileInfo to, FileInfo? from) => { - flattened = await FlattenJson(from); - } - using (ResXResourceWriter resxWriter = new ResXResourceWriter(to.FullName)) - { - foreach (KeyValuePair keyVal in flattened) + IDictionary flattened = new Dictionary(); + if (from != null) { - resxWriter.AddResource(keyVal.Key, keyVal.Value); + flattened = await FlattenJson(from); } - } + using (ResXResourceWriter resxWriter = new ResXResourceWriter(to.FullName)) + { + foreach (KeyValuePair keyVal in flattened) + { + resxWriter.AddResource(keyVal.Key, keyVal.Value); + } + } + }, destArg, fromOpt); } private async Task> FlattenJson(FileInfo jsonFile)