File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
System.CommandLine.Tests/Binding
System.CommandLine/Binding Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,21 @@ public void Command_argument_of_FileInfo_returns_null_when_argument_is_not_provi
65
65
. BeNull ( ) ;
66
66
}
67
67
68
+ [ Fact ]
69
+ public void Argument_of_FileInfo_that_is_empty_results_in_an_informative_error ( )
70
+ {
71
+ var option = new Option < FileInfo > ( "--file" ) ;
72
+ var result = option . Parse ( new string [ ] { "--file" , "" } ) ;
73
+
74
+ result . Errors
75
+ . Should ( )
76
+ . ContainSingle ( )
77
+ . Which
78
+ . Message
79
+ . Should ( )
80
+ . Contain ( "Cannot parse argument '' for option '--file'" ) ;
81
+ }
82
+
68
83
[ Fact ]
69
84
public void Argument_of_array_of_FileInfo_can_be_called_without_custom_conversion_logic ( )
70
85
{
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ internal static partial class ArgumentConverter
62
62
63
63
[ typeof ( DirectoryInfo ) ] = ( string path , out object ? value ) =>
64
64
{
65
+ if ( String . IsNullOrEmpty ( path ) )
66
+ {
67
+ value = default ;
68
+ return false ;
69
+ }
65
70
value = new DirectoryInfo ( path ) ;
66
71
return true ;
67
72
} ,
@@ -80,12 +85,22 @@ internal static partial class ArgumentConverter
80
85
81
86
[ typeof ( FileInfo ) ] = ( string path , out object ? value ) =>
82
87
{
88
+ if ( String . IsNullOrEmpty ( path ) )
89
+ {
90
+ value = default ;
91
+ return false ;
92
+ }
83
93
value = new FileInfo ( path ) ;
84
94
return true ;
85
95
} ,
86
96
87
97
[ typeof ( FileSystemInfo ) ] = ( string path , out object ? value ) =>
88
98
{
99
+ if ( String . IsNullOrEmpty ( path ) )
100
+ {
101
+ value = default ;
102
+ return false ;
103
+ }
89
104
if ( Directory . Exists ( path ) )
90
105
{
91
106
value = new DirectoryInfo ( path ) ;
You can’t perform that action at this time.
0 commit comments