ImgMetadataRemover/ConsoleInterface/Program.cs

50 lines
1.9 KiB
C#
Raw Normal View History

2022-01-23 13:12:17 +00:00
using CommandLine;
using Image;
2022-01-22 17:06:10 +00:00
using Microsoft.Extensions.Logging;
2022-01-23 13:12:17 +00:00
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
2022-01-22 17:06:10 +00:00
namespace ConsoleInterface
{
internal static class Program
{
private static void Main(string[] args)
2022-01-23 13:12:17 +00:00
{
Parser.Default.ParseArguments<Options>(args).WithParsed(RunOptions);
}
private static void RunOptions(Options options)
2022-01-22 17:06:10 +00:00
{
var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
2022-01-23 13:12:17 +00:00
TaskExecutor.Logger = loggerFactory.CreateLogger(nameof(TaskExecutor));
FilesRetriever.Logger = loggerFactory.CreateLogger(nameof(FilesRetriever));
OriginalFilenameOutputFormatter.Logger =
loggerFactory.CreateLogger(nameof(OriginalFilenameOutputFormatter));
var outputFormatter = OriginalFilenameOutputFormatter.Create(options.DestinationDirectory);
var executor = TaskExecutor.Create(new TaskExecutorOptions
2022-01-22 17:06:10 +00:00
{
2022-01-23 13:12:17 +00:00
EnableCompression = options.CompressFiles is true,
OutputFormatter = outputFormatter
});
var filesRetriever = FilesRetriever.Create();
executor.ParallelCleanImages(filesRetriever.GetFilenamesFromPath(options.SourceDirectory));
}
public class Options
{
[Option('c', "compress", Required = false, HelpText = "Compress images after cleaning.", Default = true)]
public bool? CompressFiles { get; set; }
[Option('d', "dest", Required = false, HelpText = "The destination directory.", Default = "./cleaned")]
public string DestinationDirectory { get; set; }
[Value(0, MetaName = "source", HelpText = "The source directory.", Default = ".")]
public string SourceDirectory { get; set; }
2022-01-22 17:06:10 +00:00
}
}
}