Files

79 lines
2.3 KiB
C#
Raw Permalink Normal View History

2024-04-24 18:53:10 -04:00
using System;
using System.Collections.Generic;
using InfoPrint.Features;
using SabreTools.CommandLine;
using SabreTools.CommandLine.Features;
2024-04-02 11:56:27 -04:00
2024-11-04 12:14:28 -05:00
namespace InfoPrint
2024-04-02 11:56:27 -04:00
{
2024-04-24 18:53:10 -04:00
public static class Program
2024-04-02 11:56:27 -04:00
{
public static void Main(string[] args)
{
// 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)
2024-04-24 18:53:10 -04:00
{
// Standalone Options
case Help help: help.ProcessArgs(args, 0, commandSet); return;
// 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;
2024-04-24 18:53:10 -04:00
}
}
/// <summary>
/// Create the command set for the program
/// </summary>
private static CommandSet CreateCommands(MainFeature mainFeature)
{
List<string> header = [
"Information Printing Program",
string.Empty,
"InfoPrint <options> file|directory ...",
string.Empty,
];
var commandSet = new CommandSet(header);
commandSet.Add(new Help(["-?", "-h", "--help"]));
commandSet.Add(mainFeature.DebugInput);
commandSet.Add(mainFeature.HashInput);
commandSet.Add(mainFeature.FileOnlyInput);
#if NETCOREAPP
commandSet.Add(mainFeature.JsonInput);
#endif
return commandSet;
}
2024-04-02 11:56:27 -04:00
}
}