diff --git a/src/EAVFW.Extensions.CommandLine/Extensions.cs b/src/EAVFW.Extensions.CommandLine/Extensions.cs index 19592b6..e826420 100644 --- a/src/EAVFW.Extensions.CommandLine/Extensions.cs +++ b/src/EAVFW.Extensions.CommandLine/Extensions.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Collections; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.Collections.Generic; using System.CommandLine.Invocation; @@ -58,13 +59,13 @@ public static Dictionary AddArguments(this Command command) typeof(COmmandExtensions).GetMethod(nameof(CreateArgument), 1, new[] { typeof(string) }) ?.MakeGenericMethod(prop.PropertyType).Invoke(null, new object[] - { - prop.GetCustomAttribute()?.Description - }); + { + prop.GetCustomAttribute()?.Description + }); if (argument is not Argument a) continue; - + output.Add(prop.Name, a); command.Add(a); } @@ -72,7 +73,7 @@ public static Dictionary AddArguments(this Command command) return output; } - + public static Dictionary AddOptions(this Command command) { var o = new Dictionary(); @@ -105,6 +106,11 @@ public static Dictionary AddOptions(this Command command) op.AddAlias(a.Alias); } + if (typeof(IEnumerable).IsAssignableFrom(prop.PropertyType)) + { + op.AllowMultipleArgumentsPerToken = true; + } + o[prop.Name] = op; command.Add(op); @@ -139,6 +145,7 @@ Task Run(ParseResult parsed, IConsole console) { cmd.GetType().GetProperty(o.Key).SetValue(cmd, parsed.GetValueForOption(o.Value)); } + foreach (var (key, argument) in arguments) { cmd.GetType().GetProperty(key)!.SetValue(cmd, parsed.GetValueForArgument(argument)); @@ -219,4 +226,4 @@ public static async Task RunConsoleApp(this IHost host) where TApp : return app.Result; } } -} \ No newline at end of file +}