mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Created and implemented ExitCode enum
This commit is contained in:
parent
0bb8d9e84c
commit
0f4c843730
@ -8,6 +8,13 @@ using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.CLI
|
||||
{
|
||||
internal enum ExitCode
|
||||
{
|
||||
BadArguments = -1,
|
||||
Ok = 0,
|
||||
Error = 1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class to mark attributes which need validating
|
||||
/// </summary>
|
||||
@ -115,7 +122,7 @@ namespace Wabbajack.CLI
|
||||
var optionAttribute = (OptionAttribute)p.GetAttribute(typeof(OptionAttribute));
|
||||
|
||||
if (optionAttribute.Required)
|
||||
Exit(message, -1);
|
||||
Exit(message, ExitCode.BadArguments);
|
||||
else
|
||||
Log(message);
|
||||
});
|
||||
@ -156,10 +163,10 @@ namespace Wabbajack.CLI
|
||||
Console.Write(msg);
|
||||
}
|
||||
|
||||
internal static int Exit(string msg, int code)
|
||||
internal static int Exit(string msg, ExitCode code)
|
||||
{
|
||||
Log(msg);
|
||||
return code;
|
||||
return (int)code;
|
||||
}
|
||||
|
||||
internal static void LogException(Exception e, string msg)
|
||||
|
@ -7,7 +7,8 @@ namespace Wabbajack.CLI.Verbs
|
||||
public int Execute()
|
||||
{
|
||||
if (!CLIUtils.HasValidArguments(this))
|
||||
CLIUtils.Exit("The provided arguments are not valid! Check previous messages for more information", -1);
|
||||
CLIUtils.Exit("The provided arguments are not valid! Check previous messages for more information",
|
||||
ExitCode.BadArguments);
|
||||
|
||||
return Run().Result;
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ namespace Wabbajack.CLI.Verbs
|
||||
protected override async Task<int> Run()
|
||||
{
|
||||
if (Modlist != null && (!Modlist.EndsWith(Consts.ModListExtension) && !Modlist.EndsWith("modlist.txt")))
|
||||
return CLIUtils.Exit($"The file {Modlist} is not a valid modlist file!", -1);
|
||||
return CLIUtils.Exit($"The file {Modlist} is not a valid modlist file!", ExitCode.BadArguments);
|
||||
|
||||
if (Copy && Move)
|
||||
return CLIUtils.Exit("You can't set both copy and move flags!", -1);
|
||||
return CLIUtils.Exit("You can't set both copy and move flags!", ExitCode.BadArguments);
|
||||
|
||||
var isModlist = Modlist != null && Modlist.EndsWith(Consts.ModListExtension);
|
||||
|
||||
@ -80,12 +80,12 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", 1);
|
||||
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", ExitCode.Error);
|
||||
}
|
||||
|
||||
if (modlist == null)
|
||||
{
|
||||
return CLIUtils.Exit("The Modlist could not be loaded!", 1);
|
||||
return CLIUtils.Exit("The Modlist could not be loaded!", ExitCode.Error);
|
||||
}
|
||||
|
||||
CLIUtils.Log($"Modlist contains {modlist.Archives.Count} archives.");
|
||||
@ -144,18 +144,18 @@ namespace Wabbajack.CLI.Verbs
|
||||
else
|
||||
{
|
||||
if (!Directory.Exists(Mods))
|
||||
return CLIUtils.Exit($"Mods directory {Mods} does not exist!", -1);
|
||||
return CLIUtils.Exit($"Mods directory {Mods} does not exist!", ExitCode.BadArguments);
|
||||
|
||||
CLIUtils.Log($"Reading modlist.txt from {Modlist}");
|
||||
string[] modlist = File.ReadAllLines(Modlist);
|
||||
|
||||
if (modlist == null || modlist.Length == 0)
|
||||
return CLIUtils.Exit($"Provided modlist.txt file at {Modlist} is empty or could not be read!", -1);
|
||||
return CLIUtils.Exit($"Provided modlist.txt file at {Modlist} is empty or could not be read!", ExitCode.BadArguments);
|
||||
|
||||
var mods = modlist.Where(s => s.StartsWith("+")).Select(s => s.Substring(1)).ToHashSet();
|
||||
|
||||
if (mods.Count == 0)
|
||||
return CLIUtils.Exit("Counted mods from modlist.txt are 0!", -1);
|
||||
return CLIUtils.Exit("Counted mods from modlist.txt are 0!", ExitCode.BadArguments);
|
||||
|
||||
CLIUtils.Log($"Found {mods.Count} mods in modlist.txt");
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace Wabbajack.CLI.Verbs
|
||||
{
|
||||
var state = await DownloadDispatcher.Infer(Url);
|
||||
if (state == null)
|
||||
return CLIUtils.Exit($"Could not find download source for URL {Url}", 1);
|
||||
return CLIUtils.Exit($"Could not find download source for URL {Url}", ExitCode.Error);
|
||||
|
||||
DownloadDispatcher.PrepareAll(new []{state});
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace Wabbajack.CLI.Verbs
|
||||
protected override async Task<int> Run()
|
||||
{
|
||||
if (Input != null && !Input.EndsWith(Consts.ModListExtension))
|
||||
return CLIUtils.Exit($"The file {Input} does not end with {Consts.ModListExtension}!", -1);
|
||||
return CLIUtils.Exit($"The file {Input} does not end with {Consts.ModListExtension}!", ExitCode.BadArguments);
|
||||
|
||||
ModList modlist;
|
||||
|
||||
@ -38,12 +38,12 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", 1);
|
||||
return CLIUtils.Exit($"Error while loading the Modlist!\n{e}", ExitCode.Error);
|
||||
}
|
||||
|
||||
if (modlist == null)
|
||||
{
|
||||
return CLIUtils.Exit($"The Modlist could not be loaded!", 1);
|
||||
return CLIUtils.Exit($"The Modlist could not be loaded!", ExitCode.Error);
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ namespace Wabbajack.CLI.Verbs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return CLIUtils.Exit($"Error during Validation!\n{e}", 1);
|
||||
return CLIUtils.Exit($"Error during Validation!\n{e}", ExitCode.Error);
|
||||
}
|
||||
|
||||
return CLIUtils.Exit("The Modlist passed the Validation", 0);
|
||||
|
Loading…
Reference in New Issue
Block a user