|
1 | | -using BaGet.Core.Mirror; |
| 1 | +using System; |
| 2 | +using BaGet.Core.Configuration; |
| 3 | +using BaGet.Core.Entities; |
| 4 | +using BaGet.Core.Mirror; |
| 5 | +using BaGet.Core.Services; |
2 | 6 | using BaGet.Extensions; |
3 | 7 | using Gelf.Extensions.Logging; |
4 | 8 | using McMaster.Extensions.CommandLineUtils; |
5 | 9 | using Microsoft.AspNetCore; |
6 | 10 | using Microsoft.AspNetCore.Hosting; |
| 11 | +using Microsoft.EntityFrameworkCore; |
7 | 12 | using Microsoft.Extensions.DependencyInjection; |
8 | 13 | using Microsoft.Extensions.Hosting; |
9 | 14 | using Microsoft.Extensions.Logging; |
| 15 | +using Microsoft.Extensions.Options; |
10 | 16 |
|
11 | 17 | namespace BaGet |
12 | 18 | { |
@@ -35,6 +41,36 @@ await provider |
35 | 41 | .ImportAsync(); |
36 | 42 | }); |
37 | 43 | }); |
| 44 | + |
| 45 | + var optionImportPath = import.Option("-p|--path <directory>", "Directory with .nupkg files at any depth", CommandOptionType.SingleValue); |
| 46 | + import.OnExecute(async () => { |
| 47 | + var importDirectory = optionImportPath.HasValue() |
| 48 | + ? optionImportPath.Value() |
| 49 | + : "."; |
| 50 | + |
| 51 | + Console.WriteLine($"Importing packages from {importDirectory}"); |
| 52 | + var provider = CreateHostBuilder(args).Build().Services; |
| 53 | + |
| 54 | + var scopeFactory = provider.GetRequiredService<IServiceScopeFactory>(); |
| 55 | + // Run migrations if enabled |
| 56 | + var databaseOptions = provider.GetRequiredService<IOptions<BaGetOptions>>() |
| 57 | + .Value |
| 58 | + .Database; |
| 59 | + if(databaseOptions.RunMigrations) { |
| 60 | + using (var scope = scopeFactory.CreateScope()) |
| 61 | + { |
| 62 | + scope.ServiceProvider |
| 63 | + .GetRequiredService<IContext>() |
| 64 | + .Database |
| 65 | + .Migrate(); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + await provider |
| 70 | + .GetRequiredService<PackageImporter>() |
| 71 | + .ImportAsync(importDirectory, Console.Out); |
| 72 | + return 0; |
| 73 | + }); |
38 | 74 | }); |
39 | 75 |
|
40 | 76 | app.OnExecute(() => |
|
0 commit comments