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
Option.AcceptLegalFilePathsOnly should return void
  • Loading branch information
adamsitnik committed Dec 15, 2022
commit 692cd59c5e4c8978c8d6f15b44ad466ff0056503
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ System.CommandLine
.ctor(System.String name, Func<T> defaultValueFactory, System.String description = null)
.ctor(System.String[] aliases, Func<T> defaultValueFactory, System.String description = null)
public Option<T> AcceptLegalFileNamesOnly()
public Option<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/OptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ public void Option_of_enum_can_limit_enum_members_as_valid_values()
public void Option_of_T_fluent_APIs_return_Option_of_T()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might as well remove the test

{
Option<string> option = new Option<string>("--path")
.AcceptLegalFileNamesOnly()
.AcceptLegalFilePathsOnly();
.AcceptLegalFileNamesOnly();

option.Should().BeOfType<Option<string>>();
}
Expand Down
9 changes: 7 additions & 2 deletions src/System.CommandLine.Tests/ParsingValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,11 @@ public void LegalFilePathsOnly_rejects_command_arguments_containing_invalid_path
[Fact]
public void LegalFilePathsOnly_rejects_option_arguments_containing_invalid_path_characters()
{
Option<string> option = new ("-x");
option.AcceptLegalFilePathsOnly();
var command = new Command("the-command")
{
new Option<string>("-x").AcceptLegalFilePathsOnly()
option
};

var invalidCharacter = Path.GetInvalidPathChars().First(c => c != '"');
Expand Down Expand Up @@ -620,9 +622,12 @@ public void LegalFilePathsOnly_accepts_command_arguments_containing_valid_path_c
[Fact]
public void LegalFilePathsOnly_accepts_option_arguments_containing_valid_path_characters()
{
Option<string[]> option = new ("-x");
option.AcceptLegalFilePathsOnly();

var command = new Command("the-command")
{
new Option<string[]>("-x").AcceptLegalFilePathsOnly()
option
};

var validPathName = Directory.GetCurrentDirectory();
Expand Down
6 changes: 1 addition & 5 deletions src/System.CommandLine/Option{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ public void SetDefaultValueFactory(Func<T> defaultValueFactory) =>
/// Configures the option to accept only values representing legal file paths.
/// </summary>
/// <returns>The configured option.</returns>
public Option<T> AcceptLegalFilePathsOnly()
{
_argument.AcceptLegalFilePathsOnly();
return this;
}
public void AcceptLegalFilePathsOnly() => _argument.AcceptLegalFilePathsOnly();

/// <summary>
/// Configures the option to accept only values representing legal file names.
Expand Down