Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/System.CommandLine.Tests/Binding/TypeConversionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public void Command_argument_of_FileInfo_returns_null_when_argument_is_not_provi
.BeNull();
}

[Fact]
public void Argument_of_FileInfo_that_is_empty_results_in_an_informative_error()
{
var option = new Option<FileInfo>("--file");
var result = option.Parse(new string[] { "--file", "" });

result.Errors
.Should()
.ContainSingle()
.Which
.Message
.Should()
.Contain("Cannot parse argument '' for option '--file'");
}

[Fact]
public void Argument_of_array_of_FileInfo_can_be_called_without_custom_conversion_logic()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ internal static partial class ArgumentConverter

[typeof(DirectoryInfo)] = (string path, out object? value) =>
{
if (String.IsNullOrEmpty(path))
{
value = default;
return false;
}
value = new DirectoryInfo(path);
return true;
},
Expand All @@ -80,12 +85,22 @@ internal static partial class ArgumentConverter

[typeof(FileInfo)] = (string path, out object? value) =>
{
if (String.IsNullOrEmpty(path))
{
value = default;
return false;
}
value = new FileInfo(path);
return true;
},

[typeof(FileSystemInfo)] = (string path, out object? value) =>
{
if (String.IsNullOrEmpty(path))
{
value = default;
return false;
}
if (Directory.Exists(path))
{
value = new DirectoryInfo(path);
Expand Down