mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #491 from erri120/cli-arg-verify
New CLI Verb: Validate
This commit is contained in:
commit
f8fa319e03
@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
78
Wabbajack.CLI/Verbs/Validate.cs
Normal file
78
Wabbajack.CLI/Verbs/Validate.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user