-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
58 lines (51 loc) · 1.69 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Globalization;
using dis.CommandLineApp;
using dis.CommandLineApp.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Expressions;
using Serilog.Settings.Configuration;
using Spectre.Console;
using Spectre.Console.Cli;
if (args.Length is 0) args = ["--help"];
var consoleLoggerConfigExtension = typeof(ConsoleLoggerConfigurationExtensions).Assembly;
var serilogExpression = typeof(SerilogExpression).Assembly;
ConfigurationReaderOptions options = new(consoleLoggerConfigExtension, serilogExpression);
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
IServiceCollection collection = new ServiceCollection();
HostBuilder hostBuilder = new();
hostBuilder.ConfigureServices((_, services) =>
{
services.AddMyServices();
collection = services;
});
hostBuilder.UseSerilog((context, configuration) =>
configuration
.ReadFrom.Configuration(context.Configuration, options)
.Enrich.FromLogContext()
.WriteTo.Console());
hostBuilder.Build();
TypeRegistrar registrar = new(collection);
CommandApp<RootCommand> app = new(registrar);
app.Configure(config =>
{
#if DEBUG
config.PropagateExceptions();
config.ValidateExamples();
#endif
config.AddExample("-i", "https://youtu.be/hT_nvWreIhg");
config.AddExample("-i", "https://youtu.be/hT_nvWreIhg", "-t", "73.25-110");
config.AddExample("-i", "https://youtu.be/hT_nvWreIhg", "-o",
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)));
config.SetApplicationName("dis");
});
try
{
await app.RunAsync(args);
}
catch (CommandAppException e)
{
AnsiConsole.WriteLine(e.Message);
throw;
}