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
remove Middleware
  • Loading branch information
adamsitnik committed Mar 16, 2023
commit 054106c6e02afcd74a898ce747dda43a71a58dbe
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ System.CommandLine
.ctor(Command rootCommand)
public Command Command { get; }
public System.Collections.Generic.List<Directive> Directives { get; }
public CommandLineBuilder AddMiddleware(System.CommandLine.Invocation.InvocationMiddleware middleware, System.CommandLine.Invocation.MiddlewareOrder order = Default)
public CommandLineBuilder AddMiddleware(System.Action<System.CommandLine.Invocation.InvocationContext> onInvoke, System.CommandLine.Invocation.MiddlewareOrder order = Default)
public CommandLineConfiguration Build()
public CommandLineBuilder CancelOnProcessTermination(System.Nullable<System.TimeSpan> timeout = null)
public CommandLineBuilder EnablePosixBundling(System.Boolean value = True)
Expand All @@ -85,7 +83,7 @@ System.CommandLine
public CommandLineBuilder UseVersionOption(System.String name, System.String[] aliases)
public class CommandLineConfiguration
public static CommandLineBuilder CreateBuilder(Command rootCommand)
.ctor(Command command, System.Boolean enablePosixBundling = True, System.Boolean enableTokenReplacement = True, System.Collections.Generic.IReadOnlyList<System.CommandLine.Invocation.InvocationMiddleware> middlewarePipeline = null, System.Func<System.CommandLine.Invocation.InvocationContext,System.CommandLine.Help.HelpBuilder> helpBuilderFactory = null, System.CommandLine.Parsing.TryReplaceToken tokenReplacer = null)
.ctor(Command command, System.Boolean enablePosixBundling = True, System.Boolean enableTokenReplacement = True, System.Func<System.CommandLine.Invocation.InvocationContext,System.CommandLine.Help.HelpBuilder> helpBuilderFactory = null, System.CommandLine.Parsing.TryReplaceToken tokenReplacer = null)
public System.Collections.Generic.IReadOnlyList<Directive> Directives { get; }
public System.Boolean EnablePosixBundling { get; }
public System.Boolean EnableTokenReplacement { get; }
Expand Down Expand Up @@ -246,16 +244,6 @@ System.CommandLine.Invocation
public System.CommandLine.ParseResult ParseResult { get; set; }
public T GetValue<T>(Option<T> option)
public T GetValue<T>(Argument<T> argument)
public delegate InvocationMiddleware : System.MulticastDelegate, System.ICloneable, System.Runtime.Serialization.ISerializable
.ctor(System.Object object, System.IntPtr method)
public System.IAsyncResult BeginInvoke(InvocationContext context, System.Threading.CancellationToken cancellationToken, System.Func<InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> next, System.AsyncCallback callback, System.Object object)
public System.Threading.Tasks.Task EndInvoke(System.IAsyncResult result)
public System.Threading.Tasks.Task Invoke(InvocationContext context, System.Threading.CancellationToken cancellationToken, System.Func<InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> next)
public enum MiddlewareOrder : System.Enum, System.IComparable, System.IConvertible, System.IFormattable
Default=0
ErrorReporting=1000
ExceptionHandler=-2000
Configuration=-1000
System.CommandLine.IO
public interface IStandardError
public IStandardStreamWriter Error { get; }
Expand Down
3 changes: 1 addition & 2 deletions src/System.CommandLine.DragonFruit/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private static CommandLineConfiguration BuildConfiguration(MethodInfo method,
var builder = new CommandLineBuilder(new RootCommand())
.ConfigureRootCommandFromMethod(method, target)
.ConfigureHelpFromXmlComments(method, xmlDocsFilePath)
.UseDefaults()
.UseAnsiTerminalWhenAvailable();
.UseDefaults();

return builder.Build();
}
Expand Down
90 changes: 0 additions & 90 deletions src/System.CommandLine.Hosting.Tests/HostingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,55 +289,6 @@ public async static Task GetInvocationContext_in_ConfigureServices_returns_non_n
ctxAsserted.Should().BeTrue();
}

[Fact]
public static void GetInvocationContext_returns_same_instance_as_outer_middleware()
{
InvocationContext ctxCustom = null;
InvocationContext ctxHosting = null;

var config = new CommandLineBuilder(new RootCommand())
.AddMiddleware((context, cancellationToken, next) =>
{
ctxCustom = context;
return next(context, cancellationToken);
})
.UseHost(hostBuilder =>
{
ctxHosting = hostBuilder.GetInvocationContext();
})
.Build();

_ = config.Invoke(string.Empty);

ctxHosting.Should().BeSameAs(ctxCustom);
}

[Fact]
public static void GetInvocationContext_in_ConfigureServices_returns_same_instance_as_outer_middleware()
{
InvocationContext ctxCustom = null;
InvocationContext ctxConfigureServices = null;

var config = new CommandLineBuilder(new RootCommand())
.AddMiddleware((context, cancellationToken, next) =>
{
ctxCustom = context;
return next(context, cancellationToken);
})
.UseHost(hostBuilder =>
{
hostBuilder.ConfigureServices((hostingCtx, services) =>
{
ctxConfigureServices = hostingCtx.GetInvocationContext();
});
})
.Build();

_ = config.Invoke(string.Empty);

ctxConfigureServices.Should().BeSameAs(ctxCustom);
}

[Fact]
public static void GetInvocationContext_throws_if_not_within_invocation()
{
Expand All @@ -362,46 +313,5 @@ public static void GetInvocationContext_in_ConfigureServices_throws_if_not_withi
})
.Should().Throw<InvalidOperationException>();
}

[Fact]
public static void GetHost_returns_non_null_instance_in_subsequent_middleware()
{
bool hostAsserted = false;
var config = new CommandLineBuilder(new RootCommand())
.UseHost()
.AddMiddleware((invCtx, cancellationToken, next) =>
{
IHost host = invCtx.GetHost();
host.Should().NotBeNull();
hostAsserted = true;

return next(invCtx, cancellationToken);
})
.Build();

_ = config.Invoke(string.Empty);

hostAsserted.Should().BeTrue();
}

[Fact]
public static void GetHost_returns_null_when_no_host_in_invocation()
{
bool hostAsserted = false;
var config = new CommandLineBuilder(new RootCommand())
.AddMiddleware((invCtx, cancellationToken, next) =>
{
IHost host = invCtx.GetHost();
host.Should().BeNull();
hostAsserted = true;

return next(invCtx, cancellationToken);
})
.Build();

_ = config.Invoke(string.Empty);

hostAsserted.Should().BeTrue();
}
}
}
2 changes: 1 addition & 1 deletion src/System.CommandLine.Hosting/InvocationLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
}, this);
}

// The token comes from HostingExtensions.UseHost middleware
// The token comes from HostingAction.InvokeAsync
// and it's the invocation cancellation token.
invokeCancelReg = cancellationToken.Register(state =>
{
Expand Down
25 changes: 0 additions & 25 deletions src/System.CommandLine.Rendering.Tests/TerminalModeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@ public void Sets_outputMode_to_file_when_output_is_redirected()
outputMode.Should().Be(OutputMode.PlainText);
}

[Theory]
[InlineData(OutputMode.Ansi)]
[InlineData(OutputMode.NonAnsi)]
[InlineData(OutputMode.PlainText)]
public async Task Sets_output_mode_to_Ansi_when_specified_by_output_directive(OutputMode specifiedOutputMode)
{
var console = new TestConsole();
OutputMode detectedOutputMode = OutputMode.Auto;

var command = new Command("hello");
command.SetAction((ctx, cancellationToken) =>
{
detectedOutputMode = ctx.Console.DetectOutputMode();
return Task.FromResult(0);
});

var config = new CommandLineBuilder(command)
.UseAnsiTerminalWhenAvailable()
.Build();

await config.InvokeAsync($"[output:{specifiedOutputMode}]", console);

detectedOutputMode.Should().Be(specifiedOutputMode);
}

[WindowsOnlyFact(Skip = "How to test?")]
public void Sets_outputMode_to_ansi_when_windows_and_virtual_terminal()
{
Expand Down
60 changes: 0 additions & 60 deletions src/System.CommandLine.Rendering/CommandLineBuilderExtensions.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/System.CommandLine.Tests/CommandExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@ public void Command_Invoke_can_be_called_more_than_once_for_the_same_command()
console2.Out.ToString().Should().Contain(command.Description);
}

[Fact]
public void When_CommandLineBuilder_is_used_then_Command_Invoke_does_not_use_its_configuration()
{
var command = new RootCommand();

new CommandLineBuilder(command)
.AddMiddleware(context =>
{
context.Console.Out.Write("hello!");
})
.Build();

var console = new TestConsole();

command.Invoke("", console);

console.Out
.ToString()
.Should()
.NotContain("hello!");
}

[Fact] // https://github.com/dotnet/command-line-api/issues/1589
public async Task Implicit_parsers_for_Parse_and_Invoke_do_not_affect_one_another()
{
Expand Down
Loading