Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ System.CommandLine.Hosting
public static Microsoft.Extensions.Hosting.IHost GetHost(this System.CommandLine.Invocation.InvocationContext invocationContext)
public static System.CommandLine.Invocation.InvocationContext GetInvocationContext(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder)
public static System.CommandLine.Invocation.InvocationContext GetInvocationContext(this Microsoft.Extensions.Hosting.HostBuilderContext context)
public static Microsoft.Extensions.Hosting.IHostBuilder UseCommandHandler<TCommand, THandler>(this Microsoft.Extensions.Hosting.IHostBuilder builder)
public static Microsoft.Extensions.Hosting.IHostBuilder UseCommandHandler(this Microsoft.Extensions.Hosting.IHostBuilder builder, System.Type commandType, System.Type handlerType)
public static System.CommandLine.Command UseCommandHandler<THandler>(this System.CommandLine.Command command)
public static System.CommandLine.CommandLineBuilder UseHost(this System.CommandLine.CommandLineBuilder builder, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
public static System.CommandLine.CommandLineBuilder UseHost(this System.CommandLine.CommandLineBuilder builder, System.Func<System.String[],Microsoft.Extensions.Hosting.IHostBuilder> hostBuilderFactory, System.Action<Microsoft.Extensions.Hosting.IHostBuilder> configureHost = null)
public static Microsoft.Extensions.Hosting.IHostBuilder UseInvocationLifetime(this Microsoft.Extensions.Hosting.IHostBuilder host, System.CommandLine.Invocation.InvocationContext invocation, System.Action<InvocationLifetimeOptions> configureOptions = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ System.CommandLine.NamingConventionBinder
public static ModelBinder GetOrCreateModelBinder(this System.CommandLine.Binding.BindingContext bindingContext, System.CommandLine.Binding.IValueDescriptor valueDescriptor)
public abstract class BindingHandler : System.CommandLine.CliAction
public System.CommandLine.Binding.BindingContext GetBindingContext(System.CommandLine.Invocation.InvocationContext invocationContext)
public System.CommandLine.Binding.BindingContext SetBindingContext(System.CommandLine.Binding.BindingContext bindingContext)
public static class CommandHandler
public static BindingHandler Create(System.Delegate delegate)
public static BindingHandler Create<T>(Action<T> action)
Expand Down
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 @@ -142,7 +140,7 @@ System.CommandLine
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.ParseError> Errors { get; }
public System.CommandLine.Parsing.CommandResult RootCommandResult { get; }
public System.Collections.Generic.IReadOnlyList<System.CommandLine.Parsing.Token> Tokens { get; }
public System.Collections.Generic.IReadOnlyList<System.String> UnmatchedTokens { get; }
public System.String[] UnmatchedTokens { get; }
public System.CommandLine.Parsing.ArgumentResult FindResultFor(Argument argument)
public System.CommandLine.Parsing.CommandResult FindResultFor(Command command)
public System.CommandLine.Parsing.OptionResult FindResultFor(Option option)
Expand Down Expand Up @@ -243,16 +241,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
32 changes: 12 additions & 20 deletions src/System.CommandLine.Hosting.Tests/HostingHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ namespace System.CommandLine.Hosting.Tests
{
public static class HostingHandlerTest
{

[Fact]
public static async Task Constructor_Injection_Injects_Service()
{
var service = new MyService();

var config = new CommandLineBuilder(
new MyCommand()
new MyCommand().UseCommandHandler<MyCommand.MyHandler>()
)
.UseHost((builder) => {
builder.ConfigureServices(services =>
{
services.AddTransient(x => service);
})
.UseCommandHandler<MyCommand, MyCommand.MyHandler>();
});
})
.Build();

Expand All @@ -39,14 +37,13 @@ public static async Task Constructor_Injection_Injects_Service()
[Fact]
public static async Task Parameter_is_available_in_property()
{
var config = new CommandLineBuilder(new MyCommand())
var config = new CommandLineBuilder(new MyCommand().UseCommandHandler<MyCommand.MyHandler>())
.UseHost(host =>
{
host.ConfigureServices(services =>
{
services.AddTransient<MyService>();
})
.UseCommandHandler<MyCommand, MyCommand.MyHandler>();
});
})
.Build();

Expand All @@ -60,8 +57,8 @@ public static async Task Can_have_different_handlers_based_on_command()
{
var root = new RootCommand();

root.Subcommands.Add(new MyCommand());
root.Subcommands.Add(new MyOtherCommand());
root.Subcommands.Add(new MyCommand().UseCommandHandler<MyCommand.MyHandler>());
root.Subcommands.Add(new MyOtherCommand().UseCommandHandler<MyOtherCommand.MyHandler>());
var config = new CommandLineBuilder(root)
.UseHost(host =>
{
Expand All @@ -71,9 +68,7 @@ public static async Task Can_have_different_handlers_based_on_command()
{
Action = () => 100
});
})
.UseCommandHandler<MyCommand, MyCommand.MyHandler>()
.UseCommandHandler<MyOtherCommand, MyOtherCommand.MyHandler>();
});
})
.Build();

Expand All @@ -91,15 +86,14 @@ public static async Task Can_bind_to_arguments_via_injection()
{
var service = new MyService();
var cmd = new RootCommand();
cmd.Subcommands.Add(new MyOtherCommand());
cmd.Subcommands.Add(new MyOtherCommand().UseCommandHandler<MyOtherCommand.MyHandler>());
var config = new CommandLineBuilder(cmd)
.UseHost(host =>
{
host.ConfigureServices(services =>
{
services.AddSingleton<MyService>(service);
})
.UseCommandHandler<MyOtherCommand, MyOtherCommand.MyHandler>();
});
})
.Build();

Expand All @@ -114,16 +108,14 @@ public static async Task Invokes_DerivedClass()
var service = new MyService();

var cmd = new RootCommand();
cmd.Subcommands.Add(new MyCommand());
cmd.Subcommands.Add(new MyOtherCommand());
cmd.Subcommands.Add(new MyCommand().UseCommandHandler<MyCommand.MyDerivedHandler>());
cmd.Subcommands.Add(new MyOtherCommand().UseCommandHandler<MyOtherCommand.MyDerivedHandler>());
var config = new CommandLineBuilder(cmd)
.UseHost((builder) => {
builder.ConfigureServices(services =>
{
services.AddTransient(x => service);
})
.UseCommandHandler<MyCommand, MyCommand.MyDerivedHandler>()
.UseCommandHandler<MyOtherCommand, MyOtherCommand.MyDerivedHandler>();
});
})
.Build();

Expand Down
Loading