Using OptionAttribute.Required to check if we need to exit

This commit is contained in:
erri120 2020-04-06 14:59:38 +02:00
parent 48332d67f1
commit f5082d97e6
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
3 changed files with 5 additions and 9 deletions

View File

@ -14,11 +14,6 @@ namespace Wabbajack.CLI
[AttributeUsage(AttributeTargets.Property)]
internal abstract class AValidateAttribute : Attribute
{
/// <summary>
/// Exit the application if validation failed. Will just log if set to false
/// </summary>
public bool Exit { get; set; }
/// <summary>
/// Custom message if validation failed. Use placeholder %1 to insert the value
/// </summary>
@ -117,7 +112,9 @@ namespace Wabbajack.CLI
: $"The folder {value} does not exist!"
: attribute.CustomMessage.Replace("%1", value);
if (attribute.Exit)
var optionAttribute = (OptionAttribute)p.GetAttribute(typeof(OptionAttribute));
if (optionAttribute.Required)
Exit(message, -1);
else
Log(message);

View File

@ -17,7 +17,7 @@ namespace Wabbajack.CLI.Verbs
[Verb("change-download", HelpText = "Move or Copy all used Downloads from a Modlist to another directory")]
public class ChangeDownload : AVerb
{
[IsDirectory(Exit = true, CustomMessage = "Downloads folder %1 does not exist!")]
[IsDirectory(CustomMessage = "Downloads folder %1 does not exist!")]
[Option("input", Required = true, HelpText = "Input folder containing the downloads you want to move")]
public string? Input { get; set; }
@ -25,7 +25,7 @@ namespace Wabbajack.CLI.Verbs
[Option("output", Required = true, HelpText = "Output folder the downloads should be transferred to")]
public string? Output { get; set; }
[IsFile(Exit = true, CustomMessage = "Modlist file %1 does not exist!")]
[IsFile(CustomMessage = "Modlist file %1 does not exist!")]
[Option("modlist", Required = true, HelpText = "The Modlist, can either be a .wabbajack or a modlist.txt file")]
public string? Modlist { get; set; }

View File

@ -11,7 +11,6 @@ namespace Wabbajack.CLI.Verbs
[Option('n', "name", Required = true, HelpText = @"Credential to encrypt and store in AppData\Local\Wabbajack")]
public string? Name { get; set; }
[Option('o', "output", Required = true, HelpText = @"Output file for the decrypted data")]
public string? Output { get; set; }