diff --git a/Wabbajack.CLI/OptionsDefinition.cs b/Wabbajack.CLI/OptionsDefinition.cs index 131927bc..5cf11f0d 100644 --- a/Wabbajack.CLI/OptionsDefinition.cs +++ b/Wabbajack.CLI/OptionsDefinition.cs @@ -5,9 +5,8 @@ namespace Wabbajack.CLI { public class OptionsDefinition { - public static Type[] AllOptions = new[] - { - typeof(OptionsDefinition), typeof(Encrypt), typeof(Decrypt) + public static Type[] AllOptions = { + typeof(OptionsDefinition), typeof(Encrypt), typeof(Decrypt), typeof(Validate) }; } } diff --git a/Wabbajack.CLI/Program.cs b/Wabbajack.CLI/Program.cs index 97f0c1d8..9d0c3236 100644 --- a/Wabbajack.CLI/Program.cs +++ b/Wabbajack.CLI/Program.cs @@ -1,17 +1,17 @@ -using System; -using CommandLine; +using CommandLine; using Wabbajack.CLI.Verbs; namespace Wabbajack.CLI { - class Program + public class Program { - static int Main(string[] args) + private static int Main(string[] args) { - return CommandLine.Parser.Default.ParseArguments(args, OptionsDefinition.AllOptions) + return Parser.Default.ParseArguments(args, OptionsDefinition.AllOptions) .MapResult( (Encrypt opts) => Encrypt.Run(opts), (Decrypt opts) => Decrypt.Run(opts), + (Validate opts) => Validate.Run(opts), errs => 1); } } diff --git a/Wabbajack.CLI/Verbs/Validate.cs b/Wabbajack.CLI/Verbs/Validate.cs new file mode 100644 index 00000000..8d61debb --- /dev/null +++ b/Wabbajack.CLI/Verbs/Validate.cs @@ -0,0 +1,78 @@ +using System; +using System.Reactive.Linq; +using CommandLine; +using Wabbajack.Common; +using Wabbajack.Lib; +using Wabbajack.Lib.Validation; +using File = Alphaleonis.Win32.Filesystem.File; + +namespace Wabbajack.CLI.Verbs +{ + [Verb("validate", HelpText = @"Validates a Modlist")] + public class Validate + { + [Option('i', "input", Required = true, HelpText = @"Modlist file")] + public string Input { get; set; } + + /// + /// Runs the Validation of a Modlist + /// + /// + /// + /// + /// -1 bad Input + /// 0 valid modlist + /// 1 broken modlist + /// + /// + public static int Run(Validate opts) + { + if (!File.Exists(opts.Input)) + { + Console.WriteLine($"The file {opts.Input} does not exist!"); + return -1; + } + + + if (!opts.Input.EndsWith(Consts.ModListExtension)) + { + Console.WriteLine($"The file {opts.Input} does not end with {Consts.ModListExtension}!"); + return -1; + } + + ModList modlist; + + try + { + modlist = AInstaller.LoadFromFile(opts.Input); + } + catch (Exception e) + { + Console.WriteLine($"Error while loading the Modlist!\n{e}"); + return 1; + } + + if (modlist == null) + { + Console.WriteLine($"The Modlist could not be loaded!"); + return 1; + } + + + var queue = new WorkQueue(); + + try + { + ValidateModlist.RunValidation(queue, modlist).RunSynchronously(); + } + catch (Exception e) + { + Console.WriteLine($"Error during Validation!\n{e}"); + return 1; + } + + Console.WriteLine("The Modlist passed the Validation"); + return 0; + } + } +}