Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Argument.AcceptLegalFilePathsOnly should return void
  • Loading branch information
adamsitnik committed Dec 15, 2022
commit d3a8c222bfe2c2ee0458237578ca6716176aac14
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ System.CommandLine
public System.Boolean HasDefaultValue { get; }
public System.Type ValueType { get; }
public Argument<T> AcceptLegalFileNamesOnly()
public Argument<T> AcceptLegalFilePathsOnly()
public System.Void AcceptLegalFilePathsOnly()
public System.Void AcceptOnlyFromAmong(System.String[] values)
public System.Void SetDefaultValue(T value)
public System.Void SetDefaultValueFactory(Func<T> defaultValueFactory)
Expand Down
3 changes: 1 addition & 2 deletions src/System.CommandLine.Tests/ArgumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,7 @@ public void Argument_of_enum_can_limit_enum_members_as_valid_values()
public void Argument_of_T_fluent_APIs_return_Argument_of_T()
{
Argument<string> argument = new Argument<string>("--path")
.AcceptLegalFileNamesOnly()
.AcceptLegalFilePathsOnly();
.AcceptLegalFileNamesOnly();

argument.Should().BeOfType<Argument<string>>();
}
Expand Down
8 changes: 6 additions & 2 deletions src/System.CommandLine.Tests/ParsingValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,11 @@ public class PathValidity
[Fact]
public void LegalFilePathsOnly_rejects_command_arguments_containing_invalid_path_characters()
{
Argument<string> argument = new();
argument.AcceptLegalFilePathsOnly();
var command = new Command("the-command")
{
new Argument<string>().AcceptLegalFilePathsOnly()
argument
};

var invalidCharacter = Path.GetInvalidPathChars().First(c => c != '"');
Expand Down Expand Up @@ -600,9 +602,11 @@ public void LegalFilePathsOnly_rejects_option_arguments_containing_invalid_path_
[Fact]
public void LegalFilePathsOnly_accepts_command_arguments_containing_valid_path_characters()
{
Argument<string[]> argument = new ();
argument.AcceptLegalFilePathsOnly();
var command = new Command("the-command")
{
new Argument<string[]>().AcceptLegalFilePathsOnly()
argument
};

var validPathName = Directory.GetCurrentDirectory();
Expand Down
4 changes: 1 addition & 3 deletions src/System.CommandLine/Argument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void UnrecognizedArgumentError(ArgumentResult argumentResult)
/// Configures the argument to accept only values representing legal file paths.
/// </summary>
/// <returns>The configured argument.</returns>
public Argument<T> AcceptLegalFilePathsOnly()
public void AcceptLegalFilePathsOnly()
{
var invalidPathChars = Path.GetInvalidPathChars();

Expand All @@ -225,8 +225,6 @@ public Argument<T> AcceptLegalFilePathsOnly()
}
}
});

return this;
}

/// <summary>
Expand Down