Files
SabreTools.Hashing/Hasher/Program.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2025-10-05 20:31:15 -04:00
using System;
using System.Collections.Generic;
using Hasher.Features;
2025-10-05 19:47:02 -04:00
using SabreTools.CommandLine;
using SabreTools.CommandLine.Features;
namespace Hasher
{
public static class Program
{
2025-10-05 19:47:02 -04:00
public static void Main(string[] args)
{
// Create the command set
2025-10-07 09:01:12 -04:00
var mainFeature = new MainFeature();
var commandSet = CreateCommands(mainFeature);
// If we have no args, show the help and quit
2026-01-25 17:12:44 -05:00
if (args is null || args.Length == 0)
{
2025-10-05 20:31:15 -04:00
commandSet.OutputAllHelp();
2025-10-05 19:47:02 -04:00
return;
}
// Cache the first argument and starting index
2025-10-05 19:47:02 -04:00
string featureName = args[0];
2025-10-06 11:31:54 -04:00
// Try processing the standalone arguments
var topLevel = commandSet.GetTopLevel(featureName);
2025-10-06 11:31:54 -04:00
switch (topLevel)
{
2025-10-07 09:01:12 -04:00
// Standalone Options
2025-10-06 11:31:54 -04:00
case Help help: help.ProcessArgs(args, 0, commandSet); return;
case ListFeature lf: lf.Execute(); return;
2025-10-07 09:01:12 -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();
2025-10-06 11:31:54 -04:00
break;
}
}
/// <summary>
/// Create the command set for the program
/// </summary>
2025-10-07 09:01:12 -04:00
private static CommandSet CreateCommands(MainFeature mainFeature)
{
List<string> header = [
"File Hashing Program",
string.Empty,
"Hasher <options> file|directory ...",
string.Empty,
];
List<string> footer = [
string.Empty,
"If no hash types are provided, this tool will default to",
"outputting CRC-32, MD5, SHA-1, and SHA-256.",
"Optionally, all supported hashes can be output by",
"specifying a value of 'all'.",
];
var commandSet = new CommandSet(header, footer);
2025-10-06 11:31:54 -04:00
// Standalone Options
2025-10-07 09:01:12 -04:00
commandSet.Add(new Help(["-?", "-h", "--help"]));
commandSet.Add(new ListFeature());
2025-10-06 11:31:54 -04:00
// Hasher Options
2025-10-07 09:01:12 -04:00
commandSet.Add(mainFeature.DebugInput);
commandSet.Add(mainFeature.TypeInput);
return commandSet;
}
}
}