Skip to content

Commit 9197564

Browse files
committed
unify CustomParser and DefaultValueFactory via new SetValueFactory API
1 parent d281252 commit 9197564

7 files changed

Lines changed: 1113 additions & 34 deletions

File tree

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; }
@@ -99,6 +100,7 @@
99100
public Option<T> AcceptLegalFileNamesOnly()
100101
public Option<T> AcceptLegalFilePathsOnly()
101102
public Option<T> AcceptOnlyFromAmong(System.String[] values)
103+
public System.Void SetValueFactory(Func<System.CommandLine.Parsing.ArgumentResult,T> valueFactory, ValueFactoryInvocation invocation = WhenTokensMatched)
102104
public static class OptionValidation
103105
public static Option<System.IO.FileInfo> AcceptExistingOnly(this Option<System.IO.FileInfo> option)
104106
public static Option<System.IO.DirectoryInfo> AcceptExistingOnly(this Option<System.IO.DirectoryInfo> option)
@@ -148,6 +150,10 @@
148150
public System.Collections.Generic.IEnumerable<Symbol> Parents { get; }
149151
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
150152
public System.String ToString()
153+
public enum ValueFactoryInvocation : System.Enum, System.IComparable, System.IConvertible, System.IFormattable, System.ISpanFormattable
154+
WhenTokensMatched=1
155+
WhenTokensNotMatched=2
156+
Always=3
151157
public class VersionOption : Option
152158
.ctor()
153159
.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)