using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using CommandLine; using CSharpx; namespace agbidx { [Verb("pokemon", HelpText = "Parse a combination of Pokémon front- and backsprite, and output two files respectively.")] class PokespriteOptions { [Option('i', "input-files", Required = true, HelpText = "Input images to be processed")] public IEnumerable Input {get;set;} [Option('o', "output-directory", Default = ".", Required = false, HelpText = "Output directory for the processed images, defaults to current directory")] public string OutputDirectory{get;set;} [Option('v', "verbose", Default = false, Required = false, HelpText = "Show Verbose information")] public bool Verbose{get;set;} [Option('r', "recursive", Default = false, Required = false, HelpText = "Recursively scan directories for images, by default only one level is scanned, if an input argument is a directory")] public bool Recursive{get;set;} } class Program { static async Task Main(string[] args) { return await CommandLine.Parser.Default.ParseArguments(args) .MapResult( async (PokespriteOptions opts) => await RunPokespritesAndReturnExitCode(opts), async (IEnumerable errs) => await Task.Run(() => 1)); } static async Task RunPokespritesAndReturnExitCode(PokespriteOptions opts) { try { if(!Directory.Exists(opts.OutputDirectory)) Directory.CreateDirectory(opts.OutputDirectory); await Task.WhenAll(opts.Input.Select(s => ImageLib.BitmapProcessor.ProcessPokemonImage(opts.OutputDirectory, s, opts.Verbose, true, opts.Recursive))); return 0; } catch(Exception ex) { Console.WriteLine("An error occured: " + ex.Message); return 1; } } } }