-
-
Notifications
You must be signed in to change notification settings - Fork 262
Adddresses #408 - Expand Microsoft.Extentions.Hosting... #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||||||||||||||||
// Copyright (c) Nate McMaster. | ||||||||||||||||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||||||||||||||||
|
||||||||||||||||||||
namespace Microsoft.Extensions.Hosting | ||||||||||||||||||||
{ | ||||||||||||||||||||
using System; | ||||||||||||||||||||
using System.Runtime.ExceptionServices; | ||||||||||||||||||||
using System.Threading; | ||||||||||||||||||||
using System.Threading.Tasks; | ||||||||||||||||||||
using McMaster.Extensions.CommandLineUtils; | ||||||||||||||||||||
using McMaster.Extensions.Hosting.CommandLine.Internal; | ||||||||||||||||||||
using Microsoft.Extensions.DependencyInjection; | ||||||||||||||||||||
Comment on lines
+6
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nit-pick: can you move usings to the top of the file instead of nesting inside the namespace? Sorry VS doesn't provide a way to enforce this style consistently :-/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. I think you can set that in .editorconfig There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion! I've added to editorconfig. |
||||||||||||||||||||
|
||||||||||||||||||||
/// <summary> | ||||||||||||||||||||
/// Extension methods for <see cref="IHost" /> support. | ||||||||||||||||||||
/// </summary> | ||||||||||||||||||||
public static class HostExtensions | ||||||||||||||||||||
{ | ||||||||||||||||||||
/// <summary> | ||||||||||||||||||||
/// Runs an instance of <typeparamref name="TApp" /> using the <see cref="CommandLineApplication" /> previously configured in | ||||||||||||||||||||
/// <see cref="HostBuilderExtensions.UseCommandLineApplication{TApp}(IHostBuilder, string[], Action{CommandLineApplication{TApp}})"/>. | ||||||||||||||||||||
/// </summary> | ||||||||||||||||||||
/// <typeparam name="TApp">The type of the command line application implementation</typeparam> | ||||||||||||||||||||
/// <param name="host">This instance</param> | ||||||||||||||||||||
/// <param name="cancellationToken">A cancellation token</param> | ||||||||||||||||||||
public static async Task<int> RunCommandLineApplicationAsync<TApp>( | ||||||||||||||||||||
this IHost host, | ||||||||||||||||||||
CancellationToken cancellationToken = default) | ||||||||||||||||||||
where TApp : class | ||||||||||||||||||||
{ | ||||||||||||||||||||
var exceptionHandler = host.Services.GetService<StoreExceptionHandler>(); | ||||||||||||||||||||
var state = host.Services.GetRequiredService<CommandLineState>(); | ||||||||||||||||||||
|
||||||||||||||||||||
await host.RunAsync(cancellationToken); | ||||||||||||||||||||
|
||||||||||||||||||||
if (exceptionHandler?.StoredException != null) | ||||||||||||||||||||
{ | ||||||||||||||||||||
ExceptionDispatchInfo.Capture(exceptionHandler.StoredException).Throw(); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+31
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to duplicate CommandLineUtils/src/Hosting.CommandLine/HostBuilderExtensions.cs Lines 85 to 93 in df0a511
Task<int> RunCommandLineApplicationAsync method could be replaced with two chained calls to new API you are proposing in this PR.
|
||||||||||||||||||||
return state.ExitCode; | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
#nullable enable | ||
static Microsoft.Extensions.Hosting.HostBuilderExtensions.UseCommandLineApplication<TApp>(this Microsoft.Extensions.Hosting.IHostBuilder! hostBuilder, string![]! args, System.Action<McMaster.Extensions.CommandLineUtils.CommandLineApplication<TApp!>!>! configure = null) -> Microsoft.Extensions.Hosting.IHostBuilder! | ||
Microsoft.Extensions.Hosting.HostExtensions | ||
static Microsoft.Extensions.Hosting.HostExtensions.RunCommandLineApplicationAsync<TApp>(this Microsoft.Extensions.Hosting.IHost! host, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<int>! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be largely a duplication of
CommandLineUtils/src/Hosting.CommandLine/HostBuilderExtensions.cs
Lines 60 to 83 in df0a511