~ruther/NosTale-Anonymizer

e12e5db0075652fac50d16997d9902284ef535fb — František Boháček 2 years ago fec46c0
feat: add support for output directory, matching the name of input
1 files changed, 36 insertions(+), 6 deletions(-)

M src/Anonymizer.CLI/Program.cs
M src/Anonymizer.CLI/Program.cs => src/Anonymizer.CLI/Program.cs +36 -6
@@ 33,14 33,39 @@ public static class Program
        return Parser.Default.ParseArguments<Options>(args)
            .MapResult
            (
                options => MakeAsync
                        (new FileInfo(options.Input), new FileInfo(options.Output), new FileInfo(options.Config))
                    .GetAwaiter().GetResult(),
                options =>
                {
                    var directoryInfo = new DirectoryInfo(options.Output);
                    var fileInfo = new FileInfo(options.Output);
                    if (Directory.Exists(options.Output))
                    {
                        fileInfo = null;
                    }
                    else
                    {
                        directoryInfo = null;
                    }

                    return MakeAsync
                        (
                            new FileInfo(options.Input),
                            directoryInfo,
                            fileInfo,
                            new FileInfo(options.Config)
                        )
                        .GetAwaiter().GetResult();
                },
                _ => 1
            );
    }

    private static async Task<int> MakeAsync(FileInfo input, FileInfo output, FileInfo config)
    private static async Task<int> MakeAsync
    (
        FileInfo input,
        DirectoryInfo? outputDirectory,
        FileInfo? outputFile,
        FileInfo config
    )
    {
        if (!input.Exists)
        {


@@ 48,7 73,12 @@ public static class Program
            return 1;
        }

        if (output.Exists)
        if (outputFile is null)
        {
            outputFile = new FileInfo(Path.Join(outputDirectory!.FullName, input.Name));
        }

        if (outputFile.Exists)
        {
            Console.Error.WriteLine("The output file already exists.");
            return 1;


@@ 76,7 106,7 @@ public static class Program
        using var fileSink = new FileSink
        (
            input.FullName,
            output.FullName,
            outputFile.FullName,
            services.GetRequiredService<IOptions<FileSinkOptions>>().Value
        );


Do not follow this link