This commit is contained in:
stam 2021-01-19 19:11:27 +03:00
parent 42aec2a48c
commit f57c6e3986

View File

@ -1,48 +1,48 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Serilog; using Serilog;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace EpicMorg.Atlassian.Downloader namespace EpicMorg.Atlassian.Downloader
{ {
public class Program public class Program
{ {
/// <summary> /// <summary>
/// Atlassian archive downloader. See https://github.com/EpicMorg/atlassian-downloader for more info /// Atlassian archive downloader. See https://github.com/EpicMorg/atlassian-downloader for more info
/// </summary> /// </summary>
/// <param name="Action">Action to perform</param> /// <param name="Action">Action to perform</param>
/// <param name="OutputDir">Override output directory to download.</param> /// <param name="OutputDir">Override output directory to download.</param>
/// <param name="customFeed">Override URIs to import.</param> /// <param name="customFeed">Override URIs to import.</param>
static async Task Main(string OutputDir = "atlassian", Uri[] customFeed = null, DownloadAction Action = DownloadAction.Download) => await static async Task Main(string OutputDir = "atlassian", Uri[] customFeed = null, DownloadAction Action = DownloadAction.Download) => await
Host Host
.CreateDefaultBuilder() .CreateDefaultBuilder()
.ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables()) .ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables())
.ConfigureAppConfiguration((ctx, configuration) => .ConfigureAppConfiguration((ctx, configuration) =>
configuration configuration
.SetBasePath(Environment.CurrentDirectory) .SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()) .AddEnvironmentVariables())
.ConfigureServices((ctx, services) => services .ConfigureServices((ctx, services) => services
.AddOptions() .AddOptions()
.AddLogging(builder => .AddLogging(builder =>
{ {
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(ctx.Configuration) .ReadFrom.Configuration(ctx.Configuration)
.CreateLogger(); .CreateLogger();
builder builder
.ClearProviders() .ClearProviders()
.AddSerilog(dispose: true); .AddSerilog(dispose: true);
}) })
.AddHostedService<DonloaderService>() .AddHostedService<DonloaderService>()
.AddSingleton(new DownloaderOptions(OutputDir, customFeed, Action)) .AddSingleton(new DownloaderOptions(OutputDir, customFeed, Action))
.AddHttpClient()) .AddHttpClient())
.RunConsoleAsync() .RunConsoleAsync()
.ConfigureAwait(false); .ConfigureAwait(false);
} }
} }