wabbajack/Wabbajack.CLI/Verbs/Validate.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2020-02-08 18:03:49 +00:00
using System;
using System.Threading.Tasks;
2020-02-08 18:03:49 +00:00
using CommandLine;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.Validation;
namespace Wabbajack.CLI.Verbs
{
[Verb("validate", HelpText = @"Validates a Modlist")]
public class Validate : AVerb
2020-02-08 18:03:49 +00:00
{
2020-04-06 13:20:14 +00:00
[IsFile(CustomMessage = "The modlist file %1 does not exist!", Extension = Consts.ModListExtension)]
2020-02-08 18:03:49 +00:00
[Option('i', "input", Required = true, HelpText = @"Modlist file")]
2020-04-06 12:04:40 +00:00
public string? Input { get; set; }
2020-02-08 18:03:49 +00:00
/// <summary>
/// Runs the Validation of a Modlist
/// </summary>
2020-04-06 13:20:14 +00:00
/// <returns></returns>
protected override async Task<int> Run()
2020-02-08 18:03:49 +00:00
{
ModList modlist;
try
{
modlist = AInstaller.LoadFromFile(Input);
2020-02-08 18:03:49 +00:00
}
2020-02-08 18:47:32 +00:00
catch (Exception e)
2020-02-08 18:03:49 +00:00
{
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", ExitCode.Error);
2020-02-08 18:03:49 +00:00
}
if (modlist == null)
2020-02-08 18:47:32 +00:00
{
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"The Modlist could not be loaded!", ExitCode.Error);
2020-02-08 18:47:32 +00:00
}
2020-02-08 18:03:49 +00:00
var queue = new WorkQueue();
try
{
ValidateModlist.RunValidation(queue, modlist).RunSynchronously();
}
2020-02-08 18:47:32 +00:00
catch (Exception e)
2020-02-08 18:03:49 +00:00
{
2020-04-06 13:09:17 +00:00
return CLIUtils.Exit($"Error during Validation!\n{e}", ExitCode.Error);
2020-02-08 18:03:49 +00:00
}
2020-02-24 17:05:42 +00:00
return CLIUtils.Exit("The Modlist passed the Validation", 0);
2020-02-08 18:03:49 +00:00
}
}
}