Created
August 3, 2020 08:55
-
-
Save carmeleve/daed7370b8dbfe7781c6dbab2d52bf96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static class Program | |
{ | |
/// <summary> | |
/// The entry point for the program. | |
/// </summary> | |
/// <param name="args">The arguments.</param> | |
/// <returns>When complete, an integer representing success (0) or failure (non-0).</returns> | |
public static async Task<int> Main(string[] args) | |
{ | |
ServiceProvider serviceProvider = BuildServiceProvider(); | |
Parser parser = BuildParser(serviceProvider); | |
return await parser.InvokeAsync(args).ConfigureAwait(false); | |
} | |
private static Parser BuildParser(ServiceProvider serviceProvider) | |
{ | |
var commandLineBuilder = new CommandLineBuilder(); | |
foreach (Command command in serviceProvider.GetServices<Command>()) | |
{ | |
commandLineBuilder.AddCommand(command); | |
} | |
return commandLineBuilder.UseDefaults().Build(); | |
} | |
private static ServiceProvider BuildServiceProvider() | |
{ | |
var services = new ServiceCollection(); | |
IConfigurationRoot config = new ConfigurationBuilder() | |
.AddJsonFile("appsettings.json") | |
.Build(); | |
services.AddSingleton<IConfiguration>(config); | |
services.AddCliCommands(); | |
return services.BuildServiceProvider(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment