~ruther/NosSmooth

ref: 398f20aea501ab079ea7b8627b4ffe622a65719f NosSmooth/Data/NosSmooth.Data.CLI/Commands/MigrateDatabaseCommand.cs -rw-r--r-- 1.9 KiB
398f20ae — František Boháček chore: update nosfiles package 3 years ago
                                                                                
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
59
60
61
62
63
//
//  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;

/// <summary>
/// Create a database from nos files.
/// </summary>
public class MigrateDatabaseCommand : CommandGroup
{
    private readonly DatabaseMigrator _migrator;
    private readonly NostaleDataParser _parser;

    /// <summary>
    /// Initializes a new instance of the <see cref="MigrateDatabaseCommand"/> class.
    /// </summary>
    /// <param name="migrator">The database migrator.</param>
    /// <param name="parser">The data parser.</param>
    public MigrateDatabaseCommand(DatabaseMigrator migrator, NostaleDataParser parser)
    {
        _migrator = migrator;
        _parser = parser;
    }

    /// <summary>
    /// Migrate the database using nos files.
    /// </summary>
    /// <param name="nostaleDataPath">The directory with nostale data files.</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    [Command("migrate")]
    public async Task<Result> 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);
    }
}
Do not follow this link