Skip to content

Commit b3f7a8c

Browse files
jonsequiturJon Sequeira
authored andcommitted
unify CustomParser and DefaultValueFactory via new SetValueFactory API
1 parent d5a39b1 commit b3f7a8c

File tree

7 files changed

+1113
-34
lines changed

7 files changed

+1113
-34
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public Func<System.CommandLine.Parsing.ArgumentResult,T> DefaultValueFactory { get; set; }
1616
public System.Boolean HasDefaultValue { get; }
1717
public System.Type ValueType { get; }
18+
public System.Void SetValueFactory(Func<System.CommandLine.Parsing.ArgumentResult,T> valueFactory, ValueFactoryInvocation invocation = WhenTokensMatched)
1819
public struct ArgumentArity : System.ValueType, System.IEquatable<ArgumentArity>
1920
public static ArgumentArity ExactlyOne { get; }
2021
public static ArgumentArity OneOrMore { get; }
@@ -101,6 +102,7 @@
101102
public Option<T> AcceptLegalFilePathsOnly()
102103
public Option<T> AcceptOnlyFromAmong(System.String[] values)
103104
public Option<T> AcceptOnlyFromAmong(System.StringComparer comparer, System.String[] values)
105+
public System.Void SetValueFactory(Func<System.CommandLine.Parsing.ArgumentResult,T> valueFactory, ValueFactoryInvocation invocation = WhenTokensMatched)
104106
public static class OptionValidation
105107
public static Option<System.IO.FileInfo> AcceptExistingOnly(this Option<System.IO.FileInfo> option)
106108
public static Option<System.IO.DirectoryInfo> AcceptExistingOnly(this Option<System.IO.DirectoryInfo> option)
@@ -150,6 +152,10 @@
150152
public System.Collections.Generic.IEnumerable<Symbol> Parents { get; }
151153
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
152154
public System.String ToString()
155+
public enum ValueFactoryInvocation : System.Enum, System.IComparable, System.IConvertible, System.IFormattable, System.ISpanFormattable
156+
WhenTokensMatched=1
157+
WhenTokensNotMatched=2
158+
Always=3
153159
public class VersionOption : Option
154160
.ctor()
155161
.ctor(System.String name, System.String[] aliases)

src/System.CommandLine.Tests/CustomParsingTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace System.CommandLine.Tests;
1515

16+
#pragma warning disable CS0618 // Tests in this class intentionally exercise the obsolete legacy parsing API.
17+
1618
public class CustomParsingTests
1719
{
1820
[Fact]
@@ -986,4 +988,6 @@ public void GetResult_by_name_can_be_used_recursively_within_custom_option_parse
986988
parseResult.GetValue<string>("--second").Should().Be("two");
987989
parseResult.GetValue<string>("--third").Should().Be("three");
988990
}
989-
}
991+
}
992+
993+
#pragma warning restore CS0618

src/System.CommandLine.Tests/System.CommandLine.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>$(NetMinimum);$(NetFrameworkMinimum)</TargetFrameworks>
55
<GenerateProgramFile>false</GenerateProgramFile>
66
<DefaultExcludesInProjectFolder>$(DefaultExcludesInProjectFolder);TestApps\**</DefaultExcludesInProjectFolder>
7-
<NoWarn>$(NoWarn);CS8632</NoWarn> <!-- Suppress nullable warning for files included as links -->
7+
<NoWarn>$(NoWarn);CS8632;CS0618</NoWarn> <!-- Suppress nullable warning for linked files and obsolete warnings for legacy API compatibility tests -->
88
</PropertyGroup>
99

1010
<ItemGroup>

0 commit comments

Comments
 (0)