Skip to content

Commit 72ace16

Browse files
authored
Remove InvocationContext (#2108)
1 parent 649ddfc commit 72ace16

File tree

52 files changed

+238
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+238
-399
lines changed

samples/RenderingPlayground/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5-
using System.CommandLine.Invocation;
5+
using System.CommandLine;
66
using System.CommandLine.IO;
77
using System.CommandLine.Rendering;
88
using System.CommandLine.Rendering.Views;
@@ -18,7 +18,7 @@ class Program
1818
/// <summary>
1919
/// Demonstrates various rendering capabilities.
2020
/// </summary>
21-
/// <param name="invocationContext"></param>
21+
/// <param name="parseResult"></param>
2222
/// <param name="sample">Renders a specified sample</param>
2323
/// <param name="height">The height of the rendering area</param>
2424
/// <param name="width">The width of the rendering area</param>
@@ -28,7 +28,7 @@ class Program
2828
/// <param name="overwrite">Overwrite the specified region. (If not, scroll.)</param>
2929
public static void Main(
3030
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
31-
InvocationContext invocationContext,
31+
ParseResult parseResult,
3232
SampleName sample = SampleName.Dir,
3333
int? height = null,
3434
int? width = null,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ System.CommandLine.Hosting
33
public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCommandLineDirectives(this Microsoft.Extensions.Configuration.IConfigurationBuilder config, System.CommandLine.ParseResult commandline, System.CommandLine.Directive directive)
44
public static class HostingExtensions
55
public static OptionsBuilder<TOptions> BindCommandLine<TOptions>(this OptionsBuilder<TOptions> optionsBuilder)
6-
public static Microsoft.Extensions.Hosting.IHost GetHost(this System.CommandLine.Invocation.InvocationContext invocationContext)
7-
public static System.CommandLine.Invocation.InvocationContext GetInvocationContext(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder)
8-
public static System.CommandLine.Invocation.InvocationContext GetInvocationContext(this Microsoft.Extensions.Hosting.HostBuilderContext context)
6+
public static Microsoft.Extensions.Hosting.IHost GetHost(this System.CommandLine.ParseResult parseResult)
7+
public static System.CommandLine.ParseResult GetParseResult(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder)
8+
public static System.CommandLine.ParseResult GetParseResult(this Microsoft.Extensions.Hosting.HostBuilderContext context)
99
public static System.CommandLine.Command UseCommandHandler<THandler>(this System.CommandLine.Command command)
1010
public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration builder, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
1111
public static System.CommandLine.CommandLineConfiguration UseHost(this System.CommandLine.CommandLineConfiguration builder, System.Func<System.String[],Microsoft.Extensions.Hosting.IHostBuilder> hostBuilderFactory, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
12-
public static Microsoft.Extensions.Hosting.IHostBuilder UseInvocationLifetime(this Microsoft.Extensions.Hosting.IHostBuilder host, System.CommandLine.Invocation.InvocationContext invocation, System.Action<InvocationLifetimeOptions> configureOptions = null)
12+
public static Microsoft.Extensions.Hosting.IHostBuilder UseInvocationLifetime(this Microsoft.Extensions.Hosting.IHostBuilder host, System.Action<InvocationLifetimeOptions> configureOptions = null)
1313
public class InvocationLifetime, Microsoft.Extensions.Hosting.IHostLifetime
1414
.ctor(Microsoft.Extensions.Options.IOptions<InvocationLifetimeOptions> options, Microsoft.Extensions.Hosting.IHostEnvironment environment, Microsoft.Extensions.Hosting.IHostApplicationLifetime applicationLifetime, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory = null)
1515
public Microsoft.Extensions.Hosting.IHostApplicationLifetime ApplicationLifetime { get; }

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
System.CommandLine.NamingConventionBinder
1515
public static class BindingContextExtensions
1616
public static System.Void AddModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, ModelBinder binder)
17-
public static System.CommandLine.Binding.BindingContext GetBindingContext(this System.CommandLine.Invocation.InvocationContext ctx)
17+
public static System.CommandLine.Binding.BindingContext GetBindingContext(this System.CommandLine.ParseResult parseResult)
1818
public static ModelBinder GetOrCreateModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, System.CommandLine.Binding.IValueDescriptor valueDescriptor)
1919
public abstract class BindingHandler : System.CommandLine.CliAction
20-
public System.CommandLine.Binding.BindingContext GetBindingContext(System.CommandLine.Invocation.InvocationContext invocationContext)
20+
public System.CommandLine.Binding.BindingContext GetBindingContext(System.CommandLine.ParseResult parseResult)
2121
public static class CommandHandler
2222
public static BindingHandler Create(System.Delegate delegate)
2323
public static BindingHandler Create<T>(Action<T> action)
@@ -114,8 +114,8 @@ System.CommandLine.NamingConventionBinder
114114
public class ModelBindingCommandHandler : BindingHandler
115115
public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.Argument argument)
116116
public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.Option option)
117-
public System.Int32 Invoke(System.CommandLine.Invocation.InvocationContext context)
118-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.Invocation.InvocationContext context, System.Threading.CancellationToken cancellationToken = null)
117+
public System.Int32 Invoke(System.CommandLine.ParseResult parseResult)
118+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null)
119119
public class ModelDescriptor
120120
public static ModelDescriptor FromType<T>()
121121
public static ModelDescriptor FromType(System.Type type)

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ System.CommandLine
3636
public static Argument<System.IO.FileSystemInfo> AcceptExistingOnly(this Argument<System.IO.FileSystemInfo> argument)
3737
public static Argument<T> AcceptExistingOnly<T>(this Argument<T> argument)
3838
public abstract class CliAction
39-
public System.Int32 Invoke(System.CommandLine.Invocation.InvocationContext context)
40-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.Invocation.InvocationContext context, System.Threading.CancellationToken cancellationToken = null)
39+
public System.Int32 Invoke(ParseResult parseResult)
40+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null)
4141
public class Command : Symbol, System.Collections.Generic.IEnumerable<Symbol>, System.Collections.IEnumerable
4242
.ctor(System.String name, System.String description = null)
4343
public CliAction Action { get; set; }
@@ -53,10 +53,10 @@ System.CommandLine
5353
public System.Collections.Generic.IEnumerator<Symbol> GetEnumerator()
5454
public ParseResult Parse(System.Collections.Generic.IReadOnlyList<System.String> args, CommandLineConfiguration configuration = null)
5555
public ParseResult Parse(System.String commandLine, CommandLineConfiguration configuration = null)
56-
public System.Void SetAction(System.Action<System.CommandLine.Invocation.InvocationContext> action)
57-
public System.Void SetAction(System.Func<System.CommandLine.Invocation.InvocationContext,System.Int32> action)
58-
public System.Void SetAction(System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> action)
59-
public System.Void SetAction(System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Int32>> action)
56+
public System.Void SetAction(System.Action<ParseResult> action)
57+
public System.Void SetAction(System.Func<ParseResult,System.Int32> action)
58+
public System.Void SetAction(System.Func<ParseResult,System.Threading.CancellationToken,System.Threading.Tasks.Task> action)
59+
public System.Void SetAction(System.Func<ParseResult,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.Int32>> action)
6060
public class CommandLineConfiguration
6161
.ctor(Command rootCommand)
6262
public System.Collections.Generic.List<Directive> Directives { get; }
@@ -190,8 +190,8 @@ System.CommandLine.Help
190190
public class HelpAction : System.CommandLine.CliAction
191191
.ctor()
192192
public HelpBuilder Builder { get; set; }
193-
public System.Int32 Invoke(System.CommandLine.Invocation.InvocationContext context)
194-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.Invocation.InvocationContext context, System.Threading.CancellationToken cancellationToken = null)
193+
public System.Int32 Invoke(System.CommandLine.ParseResult parseResult)
194+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.ParseResult parseResult, System.Threading.CancellationToken cancellationToken = null)
195195
public class HelpBuilder
196196
.ctor(System.Int32 maxWidth = 2147483647)
197197
public System.Int32 MaxWidth { get; }
@@ -235,12 +235,6 @@ System.CommandLine.Help
235235
public System.Boolean Equals(System.Object obj)
236236
public System.Boolean Equals(TwoColumnHelpRow other)
237237
public System.Int32 GetHashCode()
238-
System.CommandLine.Invocation
239-
public class InvocationContext
240-
.ctor(System.CommandLine.ParseResult parseResult)
241-
public System.CommandLine.ParseResult ParseResult { get; set; }
242-
public T GetValue<T>(Option<T> option)
243-
public T GetValue<T>(Argument<T> argument)
244238
System.CommandLine.Parsing
245239
public class ArgumentResult : SymbolResult
246240
public System.CommandLine.Argument Argument { get; }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ private static RootCommand BuildCommand()
3232
stringOption
3333
};
3434

35-
command.SetAction(ctx =>
35+
command.SetAction(parseResult =>
3636
{
37-
bool boolean = ctx.ParseResult.GetValue(boolOption);
38-
string text = ctx.ParseResult.GetValue(stringOption);
37+
bool boolean = parseResult.GetValue(boolOption);
38+
string text = parseResult.GetValue(stringOption);
3939
});
4040

4141
return command;

src/System.CommandLine.Benchmarks/DragonFruit/Perf_CommandLine_Help.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Setup()
3030
{
3131
typeof(object).GetTypeInfo().Assembly.Location,
3232
typeof(Enumerable).GetTypeInfo().Assembly.Location,
33-
typeof(System.CommandLine.Invocation.InvocationContext).GetTypeInfo().Assembly.Location
33+
typeof(System.CommandLine.ParseResult).GetTypeInfo().Assembly.Location
3434
}
3535
);
3636
_testAssembly = Assembly.Load(File.ReadAllBytes(_testAssemblyFilePath));

src/System.CommandLine.Benchmarks/DragonFruit/Perf_XmlDocReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Perf_XmlDocReader()
3131
{
3232
typeof(object).GetTypeInfo().Assembly.Location,
3333
typeof(Enumerable).GetTypeInfo().Assembly.Location,
34-
typeof(System.CommandLine.Invocation.InvocationContext).GetTypeInfo().Assembly.Location
34+
typeof(ParseResult).GetTypeInfo().Assembly.Location
3535
}
3636
);
3737

src/System.CommandLine.Benchmarks/Input/Sample1.Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Program
2828
/// <param name="overwrite">Overwrite the specified region. (If not, scroll.)</param>
2929
public static void Main(
3030
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
31-
InvocationContext invocationContext,
31+
ParseResult parseResult,
3232
SampleName sample = SampleName.Dir,
3333
int? height = null,
3434
int? width = null,

src/System.CommandLine.DragonFruit.Tests/CommandLineTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System.CommandLine.Rendering;
54
using System.IO;
65
using System.Threading.Tasks;
76
using FluentAssertions;

src/System.CommandLine.DragonFruit.Tests/ConfigureFromMethodTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.CommandLine.Binding;
5-
using System.CommandLine.Invocation;
65
using System.CommandLine.Tests.Binding;
76
using System.CommandLine.Tests.Utility;
87
using System.IO;
@@ -198,7 +197,6 @@ public async Task When_method_returns_Task_of_int_then_return_code_is_set_to_ret
198197
}
199198

200199
[Theory]
201-
[InlineData(typeof(InvocationContext))]
202200
[InlineData(typeof(BindingContext))]
203201
[InlineData(typeof(ParseResult))]
204202
[InlineData(typeof(CancellationToken))]

0 commit comments

Comments
 (0)