Skip to content

Commit e8e7b3c

Browse files
authored
Remove set handler overloads (#2089)
* remove SetHandler overloads * merge Command.SetHandler extension methods into Command * remove IValueDescriptor<T> and remove BinderBase<T>
1 parent 3e0d47c commit e8e7b3c

23 files changed

+81
-805
lines changed

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ System.CommandLine
99
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
1010
public System.Object GetDefaultValue()
1111
public System.String ToString()
12-
public class Argument<T> : Argument, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor
12+
public class Argument<T> : Argument, System.CommandLine.Binding.IValueDescriptor
1313
.ctor(System.String name)
1414
public Func<System.CommandLine.Parsing.ArgumentResult,T> CustomParser { get; set; }
1515
public Func<System.CommandLine.Parsing.ArgumentResult,T> DefaultValueFactory { get; set; }
@@ -50,6 +50,8 @@ System.CommandLine
5050
public System.Collections.Generic.IEnumerator<Symbol> GetEnumerator()
5151
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, CommandLineConfiguration configuration = null)
5252
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null)
53+
public System.Void SetHandler(System.Action<System.CommandLine.Invocation.InvocationContext> handle)
54+
public System.Void SetHandler(System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle)
5355
public static class CommandExtensions
5456
public static System.Int32 Invoke(this Command command, System.String[] args, IConsole console = null)
5557
public static System.Int32 Invoke(this Command command, System.String commandLine, IConsole console = null)
@@ -108,27 +110,6 @@ System.CommandLine
108110
public System.Void SetSynchronousHandler(System.Action<System.CommandLine.Invocation.InvocationContext> handler)
109111
public class EnvironmentVariablesDirective : Directive
110112
.ctor()
111-
public static class Handler
112-
public static System.Void SetHandler(this Command command, System.Action<System.CommandLine.Invocation.InvocationContext> handle)
113-
public static System.Void SetHandler(this Command command, System.Action handle)
114-
public static System.Void SetHandler(this Command command, System.Func<System.Threading.CancellationToken,System.Threading.Tasks.Task> handle)
115-
public static System.Void SetHandler(this Command command, System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle)
116-
public static System.Void SetHandler<T>(this Command command, Action<T> handle, IValueDescriptor<T> symbol)
117-
public static System.Void SetHandler<T>(this Command command, Func<T,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T> symbol)
118-
public static System.Void SetHandler<T1, T2>(this Command command, Action<T1,T2> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2)
119-
public static System.Void SetHandler<T1, T2>(this Command command, Func<T1,T2,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2)
120-
public static System.Void SetHandler<T1, T2, T3>(this Command command, Action<T1,T2,T3> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3)
121-
public static System.Void SetHandler<T1, T2, T3>(this Command command, Func<T1,T2,T3,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3)
122-
public static System.Void SetHandler<T1, T2, T3, T4>(this Command command, Action<T1,T2,T3,T4> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4)
123-
public static System.Void SetHandler<T1, T2, T3, T4>(this Command command, Func<T1,T2,T3,T4,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4)
124-
public static System.Void SetHandler<T1, T2, T3, T4, T5>(this Command command, Action<T1,T2,T3,T4,T5> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5)
125-
public static System.Void SetHandler<T1, T2, T3, T4, T5>(this Command command, Func<T1,T2,T3,T4,T5,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5)
126-
public static System.Void SetHandler<T1, T2, T3, T4, T5, T6>(this Command command, Action<T1,T2,T3,T4,T5,T6> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5, IValueDescriptor<T6> symbol6)
127-
public static System.Void SetHandler<T1, T2, T3, T4, T5, T6>(this Command command, Func<T1,T2,T3,T4,T5,T6,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5, IValueDescriptor<T6> symbol6)
128-
public static System.Void SetHandler<T1, T2, T3, T4, T5, T6, T7>(this Command command, Action<T1,T2,T3,T4,T5,T6,T7> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5, IValueDescriptor<T6> symbol6, IValueDescriptor<T7> symbol7)
129-
public static System.Void SetHandler<T1, T2, T3, T4, T5, T6, T7>(this Command command, Func<T1,T2,T3,T4,T5,T6,T7,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5, IValueDescriptor<T6> symbol6, IValueDescriptor<T7> symbol7)
130-
public static System.Void SetHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this Command command, Action<T1,T2,T3,T4,T5,T6,T7,T8> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5, IValueDescriptor<T6> symbol6, IValueDescriptor<T7> symbol7, IValueDescriptor<T8> symbol8)
131-
public static System.Void SetHandler<T1, T2, T3, T4, T5, T6, T7, T8>(this Command command, Func<T1,T2,T3,T4,T5,T6,T7,T8,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T1> symbol1, IValueDescriptor<T2> symbol2, IValueDescriptor<T3> symbol3, IValueDescriptor<T4> symbol4, IValueDescriptor<T5> symbol5, IValueDescriptor<T6> symbol6, IValueDescriptor<T7> symbol7, IValueDescriptor<T8> symbol8)
132113
public interface ICommandHandler
133114
public System.Int32 Invoke(System.CommandLine.Invocation.InvocationContext context)
134115
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.Invocation.InvocationContext context, System.Threading.CancellationToken cancellationToken = null)
@@ -144,7 +125,7 @@ System.CommandLine
144125
public System.Collections.Generic.List<System.Action<System.CommandLine.Parsing.OptionResult>> Validators { get; }
145126
public System.Type ValueType { get; }
146127
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
147-
public class Option<T> : Option, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor
128+
public class Option<T> : Option, System.CommandLine.Binding.IValueDescriptor
148129
.ctor(System.String name, System.String[] aliases)
149130
public Func<System.CommandLine.Parsing.ArgumentResult,T> CustomParser { get; set; }
150131
public Func<System.CommandLine.Parsing.ArgumentResult,T> DefaultValueFactory { get; set; }
@@ -191,8 +172,6 @@ System.CommandLine
191172
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
192173
public System.String ToString()
193174
System.CommandLine.Binding
194-
public abstract class BinderBase<T>, IValueDescriptor<T>, IValueDescriptor, IValueSource
195-
protected T GetBoundValue(BindingContext bindingContext)
196175
public class BindingContext, System.IServiceProvider
197176
public System.CommandLine.IConsole Console { get; }
198177
public System.CommandLine.ParseResult ParseResult { get; }
@@ -209,7 +188,6 @@ System.CommandLine.Binding
209188
public System.String ValueName { get; }
210189
public System.Type ValueType { get; }
211190
public System.Object GetDefaultValue()
212-
public interface IValueDescriptor<out T> : IValueDescriptor
213191
public interface IValueSource
214192
public System.Boolean TryGetValue(IValueDescriptor valueDescriptor, BindingContext bindingContext, ref System.Object& boundValue)
215193
System.CommandLine.Completions

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_Simple.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ private static RootCommand BuildCommand()
3333
stringOption
3434
};
3535

36-
command.SetHandler(static (bool _, string _) => { }, boolOption, stringOption);
36+
command.SetHandler(ctx =>
37+
{
38+
bool boolean = ctx.ParseResult.GetValue(boolOption);
39+
string text = ctx.ParseResult.GetValue(stringOption);
40+
});
3741

3842
return command;
3943
}

src/System.CommandLine.Suggest.Tests/EndToEndTestApp/Program.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine;
2+
using System.CommandLine.Invocation;
23
using System.CommandLine.Parsing;
34
using System.Threading.Tasks;
45
using System.Threading;
@@ -22,12 +23,15 @@ static async Task Main(string[] args)
2223
durianOption,
2324
};
2425

25-
rootCommand.SetHandler(
26-
(string apple, string banana, string cherry, string durian, CancellationToken cancellationToken) => Task.CompletedTask,
27-
appleOption,
28-
bananaOption,
29-
cherryOption,
30-
durianOption);
26+
rootCommand.SetHandler((InvocationContext ctx, CancellationToken cancellationToken) =>
27+
{
28+
string apple = ctx.ParseResult.GetValue(appleOption);
29+
string banana = ctx.ParseResult.GetValue(bananaOption);
30+
string cherry = ctx.ParseResult.GetValue(cherryOption);
31+
string durian = ctx.ParseResult.GetValue(durianOption);
32+
33+
return Task.CompletedTask;
34+
});
3135

3236
var commandLine = new CommandLineBuilder(rootCommand)
3337
.UseDefaults()

src/System.CommandLine.Tests/ArgumentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public async Task Custom_argument_parser_is_only_called_once()
378378
};
379379

380380
var command = new RootCommand();
381-
command.SetHandler((int value) => handlerWasCalled = true, option);
381+
command.SetHandler((ctx) => handlerWasCalled = true);
382382
command.Options.Add(option);
383383

384384
await command.InvokeAsync("--value 42");

0 commit comments

Comments
 (0)