Merge pull request #491 from erri120/cli-arg-verify

New CLI Verb: Validate
This commit is contained in:
Timothy Baldridge 2020-02-08 12:28:27 -07:00 committed by GitHub
commit f8fa319e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 8 deletions

View File

@ -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)
};
}
}

View File

@ -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);
}
}

View File

@ -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; }
/// <summary>
/// Runs the Validation of a Modlist
/// </summary>
/// <param name="opts"></param>
/// <returns>
/// <para>
/// <c>-1</c> bad Input
/// <c>0</c> valid modlist
/// <c>1</c> broken modlist
/// </para>
/// </returns>
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;
}
}
}