Files
SabreTools.Serialization/ExtractionTool/Program.cs

80 lines
2.4 KiB
C#
Raw Normal View History

2025-08-28 15:11:21 -04:00
using System;
using System.Collections.Generic;
using ExtractionTool.Features;
using SabreTools.CommandLine;
using SabreTools.CommandLine.Features;
2025-08-28 15:11:21 -04:00
namespace ExtractionTool
{
2025-10-07 11:25:35 -04:00
public static class Program
2025-08-28 15:11:21 -04:00
{
public static void Main(string[] args)
2025-08-28 15:11:21 -04:00
{
#if NET462_OR_GREATER || NETCOREAPP
// Register the codepages
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
// Create the command set
var mainFeature = new MainFeature();
var commandSet = CreateCommands(mainFeature);
// If we have no args, show the help and quit
2026-01-25 14:30:18 -05:00
if (args is null || args.Length == 0)
{
commandSet.OutputAllHelp();
return;
}
// Cache the first argument and starting index
string featureName = args[0];
// Try processing the standalone arguments
var topLevel = commandSet.GetTopLevel(featureName);
switch (topLevel)
{
// Standalone Options
case Help help: help.ProcessArgs(args, 0, commandSet); return;
2025-08-28 15:11:21 -04:00
// Default Behavior
default:
if (!mainFeature.ProcessArgs(args, 0))
{
commandSet.OutputAllHelp();
return;
}
else if (!mainFeature.VerifyInputs())
{
Console.Error.WriteLine("At least one input is required");
commandSet.OutputAllHelp();
return;
}
mainFeature.Execute();
break;
2025-08-28 15:11:21 -04:00
}
}
/// <summary>
/// Create the command set for the program
/// </summary>
private static CommandSet CreateCommands(MainFeature mainFeature)
{
List<string> header = [
"Extraction Tool",
string.Empty,
"ExtractionTool <options> file|directory ...",
string.Empty,
];
var commandSet = new CommandSet(header);
commandSet.Add(new Help(["-?", "-h", "--help"]));
commandSet.Add(mainFeature.DebugInput);
commandSet.Add(mainFeature.OutputPathInput);
return commandSet;
}
2025-08-28 15:11:21 -04:00
}
}