2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Collections . Generic ;
5
- using System . CommandLine . Binding ;
6
5
using System . CommandLine . Builder ;
6
+ using System . CommandLine . Invocation ;
7
7
using System . CommandLine . Parsing ;
8
8
using System . CommandLine . Tests . Binding ;
9
9
using System . IO ;
@@ -33,7 +33,7 @@ public void Option_arguments_are_bound_by_name_to_constructor_parameters(
33
33
new Option ( "--value" , argumentType : type )
34
34
} ;
35
35
36
- var bindingContext = new BindingContext ( command . Parse ( commandLine ) ) ;
36
+ var bindingContext = new InvocationContext ( command . Parse ( commandLine ) ) . BindingContext ;
37
37
38
38
var instance = binder . CreateInstance ( bindingContext ) ;
39
39
@@ -64,7 +64,7 @@ public void Command_arguments_are_bound_by_name_to_constructor_parameters(
64
64
}
65
65
} ;
66
66
67
- var bindingContext = new BindingContext ( command . Parse ( commandLine ) ) ;
67
+ var bindingContext = new InvocationContext ( command . Parse ( commandLine ) ) . BindingContext ;
68
68
69
69
var instance = binder . CreateInstance ( bindingContext ) ;
70
70
@@ -91,7 +91,7 @@ public void Command_arguments_are_bound_by_name_to_complex_constructor_parameter
91
91
}
92
92
} ;
93
93
94
- var bindingContext = new BindingContext ( command . Parse ( commandLine ) ) ;
94
+ var bindingContext = new InvocationContext ( command . Parse ( commandLine ) ) . BindingContext ;
95
95
96
96
var instance = binder . CreateInstance ( bindingContext ) ;
97
97
@@ -113,7 +113,7 @@ public void Explicitly_configured_default_values_can_be_bound_by_name_to_constru
113
113
var binder = new ModelBinder ( typeof ( ClassWithMultiLetterCtorParameters ) ) ;
114
114
115
115
var parser = new Parser ( command ) ;
116
- var bindingContext = new BindingContext ( parser . Parse ( "" ) ) ;
116
+ var bindingContext = new InvocationContext ( parser . Parse ( "" ) ) . BindingContext ;
117
117
118
118
var instance = ( ClassWithMultiLetterCtorParameters ) binder . CreateInstance ( bindingContext ) ;
119
119
@@ -139,7 +139,7 @@ public void Option_arguments_are_bound_by_name_to_property_setters(
139
139
} ;
140
140
var parser = new Parser ( command ) ;
141
141
142
- var bindingContext = new BindingContext ( parser . Parse ( commandLine ) ) ;
142
+ var bindingContext = new InvocationContext ( parser . Parse ( commandLine ) ) . BindingContext ;
143
143
144
144
var instance = binder . CreateInstance ( bindingContext ) ;
145
145
@@ -171,7 +171,7 @@ public void Command_arguments_are_bound_by_name_to_property_setters(
171
171
} ;
172
172
var parser = new Parser ( command ) ;
173
173
174
- var bindingContext = new BindingContext ( parser . Parse ( commandLine ) ) ;
174
+ var bindingContext = new InvocationContext ( parser . Parse ( commandLine ) ) . BindingContext ;
175
175
176
176
var instance = binder . CreateInstance ( bindingContext ) ;
177
177
@@ -190,7 +190,7 @@ public void Types_having_constructors_accepting_a_single_string_are_bound_using_
190
190
var command = new Command ( "the-command" ) ;
191
191
command . AddOption ( option ) ;
192
192
var binder = new ModelBinder ( typeof ( ClassWithCtorParameter < DirectoryInfo > ) ) ;
193
- var bindingContext = new BindingContext ( command . Parse ( $ "--value \" { tempPath } \" ") ) ;
193
+ var bindingContext = new InvocationContext ( command . Parse ( $ "--value \" { tempPath } \" ") ) . BindingContext ;
194
194
195
195
var instance = ( ClassWithCtorParameter < DirectoryInfo > ) binder . CreateInstance ( bindingContext ) ;
196
196
@@ -207,7 +207,7 @@ public void Explicitly_configured_default_values_can_be_bound_by_name_to_propert
207
207
var binder = new ModelBinder ( typeof ( ClassWithSetter < string > ) ) ;
208
208
209
209
var parser = new Parser ( command ) ;
210
- var bindingContext = new BindingContext ( parser . Parse ( "" ) ) ;
210
+ var bindingContext = new InvocationContext ( parser . Parse ( "" ) ) . BindingContext ;
211
211
212
212
var instance = ( ClassWithSetter < string > ) binder . CreateInstance ( bindingContext ) ;
213
213
@@ -225,8 +225,8 @@ public void Property_setters_with_no_default_value_and_no_matching_option_are_no
225
225
var binder = new ModelBinder ( typeof ( ClassWithSettersAndCtorParametersWithDifferentNames ) ) ;
226
226
227
227
var parser = new Parser ( command ) ;
228
- var bindingContext = new BindingContext (
229
- parser . Parse ( "" ) ) ;
228
+ var bindingContext = new InvocationContext (
229
+ parser . Parse ( "" ) ) . BindingContext ;
230
230
231
231
var instance = ( ClassWithSettersAndCtorParametersWithDifferentNames ) binder . CreateInstance ( bindingContext ) ;
232
232
@@ -240,7 +240,7 @@ public void Parse_result_can_be_used_to_create_an_instance_without_doing_handler
240
240
{
241
241
new Option < int > ( "--int-option" )
242
242
} ) ;
243
- var bindingContext = new BindingContext ( parser . Parse ( "the-command --int-option 123" ) ) ;
243
+ var bindingContext = new InvocationContext ( parser . Parse ( "the-command --int-option 123" ) ) . BindingContext ;
244
244
var binder = new ModelBinder ( typeof ( ClassWithMultiLetterSetters ) ) ;
245
245
246
246
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
@@ -256,7 +256,7 @@ public void Parse_result_can_be_used_to_modify_an_existing_instance_without_doin
256
256
new Option < int > ( "--int-option" )
257
257
} ) ;
258
258
var instance = new ClassWithMultiLetterSetters ( ) ;
259
- var bindingContext = new BindingContext ( parser . Parse ( "the-command --int-option 123" ) ) ;
259
+ var bindingContext = new InvocationContext ( parser . Parse ( "the-command --int-option 123" ) ) . BindingContext ;
260
260
var binder = new ModelBinder ( typeof ( ClassWithMultiLetterSetters ) ) ;
261
261
262
262
binder . UpdateInstance ( instance , bindingContext ) ;
@@ -270,7 +270,7 @@ public void Modify_an_existing_instance_should_keep_all_default_values_if_no_arg
270
270
var parser = new Parser ( new Command ( "the-command" ) ) ;
271
271
272
272
var instance = new ClassWithComplexTypes ( ) ;
273
- var bindingContext = new BindingContext ( parser . Parse ( "the-command" ) ) ;
273
+ var bindingContext = new InvocationContext ( parser . Parse ( "the-command" ) ) . BindingContext ;
274
274
var binder = new ModelBinder ( typeof ( ClassWithComplexTypes ) ) ;
275
275
276
276
binder . UpdateInstance ( instance , bindingContext ) ;
@@ -291,7 +291,7 @@ public void Values_from_options_on_parent_commands_are_bound_by_name_by_default(
291
291
292
292
var parseResult = parentCommand . Parse ( "parent-command --int-option 123 child-command" ) ;
293
293
294
- var bindingContext = new BindingContext ( parseResult ) ;
294
+ var bindingContext = new InvocationContext ( parseResult ) . BindingContext ;
295
295
296
296
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
297
297
@@ -311,7 +311,7 @@ public void Default_values_from_options_on_parent_commands_are_bound_by_name_by_
311
311
312
312
var parseResult = parentCommand . Parse ( "parent-command child-command" ) ;
313
313
314
- var bindingContext = new BindingContext ( parseResult ) ;
314
+ var bindingContext = new InvocationContext ( parseResult ) . BindingContext ;
315
315
316
316
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
317
317
@@ -334,7 +334,7 @@ public void Values_from_parent_command_arguments_are_bound_by_name_by_default()
334
334
335
335
var parseResult = parentCommand . Parse ( "parent-command 123 child-command" ) ;
336
336
337
- var bindingContext = new BindingContext ( parseResult ) ;
337
+ var bindingContext = new InvocationContext ( parseResult ) . BindingContext ;
338
338
339
339
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
340
340
@@ -357,7 +357,7 @@ public void Default_values_from_parent_command_arguments_are_bound_by_name_by_de
357
357
358
358
var parseResult = parentCommand . Parse ( "parent-command child-command" ) ;
359
359
360
- var bindingContext = new BindingContext ( parseResult ) ;
360
+ var bindingContext = new InvocationContext ( parseResult ) . BindingContext ;
361
361
362
362
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
363
363
@@ -381,7 +381,7 @@ public void Values_from_options_on_parent_commands_can_be_bound_regardless_of_na
381
381
c => c . IntOption ,
382
382
option ) ;
383
383
384
- var bindingContext = new BindingContext ( parentCommand . Parse ( "parent-command -x 123 child-command" ) ) ;
384
+ var bindingContext = new InvocationContext ( parentCommand . Parse ( "parent-command -x 123 child-command" ) ) . BindingContext ;
385
385
386
386
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
387
387
@@ -399,7 +399,7 @@ public void Arbitrary_values_can_be_bound()
399
399
c => c . IntOption ,
400
400
_ => 123 ) ;
401
401
402
- var bindingContext = new BindingContext ( command . Parse ( "the-command" ) ) ;
402
+ var bindingContext = new InvocationContext ( command . Parse ( "the-command" ) ) . BindingContext ;
403
403
404
404
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
405
405
@@ -421,7 +421,7 @@ public void PropertyInfo_can_be_bound_to_option()
421
421
propertyInfo ,
422
422
option ) ;
423
423
424
- var bindingContext = new BindingContext ( command . Parse ( "the-command --fred 42" ) ) ;
424
+ var bindingContext = new InvocationContext ( command . Parse ( "the-command --fred 42" ) ) . BindingContext ;
425
425
426
426
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
427
427
@@ -441,7 +441,7 @@ public void PropertyInfo_can_be_bound_to_argument()
441
441
442
442
binder . BindMemberFromValue ( propertyInfo , argument ) ;
443
443
444
- var bindingContext = new BindingContext ( command . Parse ( "the-command 42" ) ) ;
444
+ var bindingContext = new InvocationContext ( command . Parse ( "the-command 42" ) ) . BindingContext ;
445
445
446
446
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
447
447
@@ -461,7 +461,7 @@ public void PropertyExpression_can_be_bound_to_option()
461
461
i => i . IntOption ,
462
462
option ) ;
463
463
464
- var bindingContext = new BindingContext ( command . Parse ( "the-command --fred 42" ) ) ;
464
+ var bindingContext = new InvocationContext ( command . Parse ( "the-command --fred 42" ) ) . BindingContext ;
465
465
466
466
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
467
467
@@ -481,7 +481,7 @@ public void PropertyExpression_can_be_bound_to_argument()
481
481
i => i . IntOption ,
482
482
argument ) ;
483
483
484
- var bindingContext = new BindingContext ( command . Parse ( "the-command 42" ) ) ;
484
+ var bindingContext = new InvocationContext ( command . Parse ( "the-command 42" ) ) . BindingContext ;
485
485
486
486
var instance = ( ClassWithMultiLetterSetters ) binder . CreateInstance ( bindingContext ) ;
487
487
@@ -493,7 +493,7 @@ public void Option_argument_is_bound_to_longest_constructor()
493
493
{
494
494
var option = new Option < int > ( "--int-property" ) ;
495
495
496
- var bindingContext = new BindingContext ( option . Parse ( "--int-property 42" ) ) ;
496
+ var bindingContext = new InvocationContext ( option . Parse ( "--int-property 42" ) ) . BindingContext ;
497
497
var binder = new ModelBinder < ClassWithMultipleCtor > ( ) ;
498
498
var instance = binder . CreateInstance ( bindingContext ) as ClassWithMultipleCtor ;
499
499
@@ -508,7 +508,7 @@ public void Command_argument_is_bound_to_longest_constructor()
508
508
rootCommand . AddArgument ( new Argument < int > { Name = nameof ( ClassWithMultipleCtor . IntProperty ) } ) ;
509
509
var parser = new Parser ( rootCommand ) ;
510
510
511
- var bindingContext = new BindingContext ( parser . Parse ( "42" ) ) ;
511
+ var bindingContext = new InvocationContext ( parser . Parse ( "42" ) ) . BindingContext ;
512
512
var binder = new ModelBinder < ClassWithMultipleCtor > ( ) ;
513
513
var instance = binder . CreateInstance ( bindingContext ) as ClassWithMultipleCtor ;
514
514
@@ -523,7 +523,7 @@ public void Explicit_model_binder_binds_only_to_configured_properties()
523
523
var stringOption = new Option < string > ( "--string-property" ) ;
524
524
var parser = new Parser ( new RootCommand { intOption , stringOption } ) ;
525
525
526
- var bindingContext = new BindingContext ( parser . Parse ( "--int-property 42 --string-property Hello" ) ) ;
526
+ var bindingContext = new InvocationContext ( parser . Parse ( "--int-property 42 --string-property Hello" ) ) . BindingContext ;
527
527
var binder = new ModelBinder < ClassWithMultiLetterSetters >
528
528
{
529
529
EnforceExplicitBinding = true
0 commit comments