1
- using Microsoft . Extensions . DependencyInjection ;
1
+ using System . Collections ;
2
+ using Microsoft . Extensions . DependencyInjection ;
2
3
using Microsoft . Extensions . Hosting ;
3
4
using System . Collections . Generic ;
4
5
using System . CommandLine . Invocation ;
@@ -58,21 +59,21 @@ public static Dictionary<string, Argument> AddArguments(this Command command)
58
59
typeof ( COmmandExtensions ) . GetMethod ( nameof ( CreateArgument ) , 1 , new [ ] { typeof ( string ) } )
59
60
? . MakeGenericMethod ( prop . PropertyType ) . Invoke ( null ,
60
61
new object [ ]
61
- {
62
- prop . GetCustomAttribute < DescriptionAttribute > ( ) ? . Description
63
- } ) ;
62
+ {
63
+ prop . GetCustomAttribute < DescriptionAttribute > ( ) ? . Description
64
+ } ) ;
64
65
65
66
66
67
if ( argument is not Argument a ) continue ;
67
-
68
+
68
69
output . Add ( prop . Name , a ) ;
69
70
command . Add ( a ) ;
70
71
}
71
72
}
72
73
73
74
return output ;
74
75
}
75
-
76
+
76
77
public static Dictionary < string , Option > AddOptions ( this Command command )
77
78
{
78
79
var o = new Dictionary < string , Option > ( ) ;
@@ -105,6 +106,11 @@ public static Dictionary<string, Option> AddOptions(this Command command)
105
106
op . AddAlias ( a . Alias ) ;
106
107
}
107
108
109
+ if ( typeof ( IEnumerable ) . IsAssignableFrom ( prop . PropertyType ) )
110
+ {
111
+ op . AllowMultipleArgumentsPerToken = true ;
112
+ }
113
+
108
114
o [ prop . Name ] = op ;
109
115
110
116
command . Add ( op ) ;
@@ -139,6 +145,7 @@ Task<int> Run(ParseResult parsed, IConsole console)
139
145
{
140
146
cmd . GetType ( ) . GetProperty ( o . Key ) . SetValue ( cmd , parsed . GetValueForOption ( o . Value ) ) ;
141
147
}
148
+
142
149
foreach ( var ( key , argument ) in arguments )
143
150
{
144
151
cmd . GetType ( ) . GetProperty ( key ) ! . SetValue ( cmd , parsed . GetValueForArgument ( argument ) ) ;
@@ -219,4 +226,4 @@ public static async Task<int> RunConsoleApp<TApp>(this IHost host) where TApp :
219
226
return app . Result ;
220
227
}
221
228
}
222
- }
229
+ }
0 commit comments