// // MigrateDatabaseCommand.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Data.Abstractions.Language; using NosSmooth.Data.Database; using NosSmooth.Data.NOSFiles; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Results; namespace NosSmooth.Data.CLI.Commands; /// /// Create a database from nos files. /// public class MigrateDatabaseCommand : CommandGroup { private readonly DatabaseMigrator _migrator; private readonly NostaleDataParser _parser; /// /// Initializes a new instance of the class. /// /// The database migrator. /// The data parser. public MigrateDatabaseCommand(DatabaseMigrator migrator, NostaleDataParser parser) { _migrator = migrator; _parser = parser; } /// /// Migrate the database using nos files. /// /// The directory with nostale data files. /// A representing the asynchronous operation. [Command("migrate")] public async Task HandleMigrate([Greedy] string nostaleDataPath) { var parsingResult = _parser.ParseFiles ( nostaleDataPath, Language.Cz, Language.De, Language.Uk, Language.Es, Language.Fr, Language.It, Language.Pl, Language.Ru, Language.Tr ); if (!parsingResult.IsSuccess) { return Result.FromError(parsingResult); } return await _migrator.Migrate(parsingResult.Entity); } }