From 81b300bae6c1330634504d6a04786603b946937d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 5 Oct 2025 23:00:20 -0400 Subject: [PATCH] Add default implementation of parsing in CommandSet --- SabreTools.CommandLine/CommandSet.cs | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/SabreTools.CommandLine/CommandSet.cs b/SabreTools.CommandLine/CommandSet.cs index feb2222..78b7ee4 100644 --- a/SabreTools.CommandLine/CommandSet.cs +++ b/SabreTools.CommandLine/CommandSet.cs @@ -871,5 +871,63 @@ namespace SabreTools.CommandLine } #endregion + + #region Processing + + /// + /// Process args list with default handling + /// + /// Set of arguments to process + /// True if all arguments were processed correctly, false otherwise + /// + /// This default processing implementation assumes a few key points: + /// - Top-level items are all + /// - There is only top-level item allowed at a time + /// - The first argument is always the flag + /// + public bool ProcessArgs(string[] args) + { + // If there's no arguments, show help + if (args.Length == 0) + { + OutputGenericHelp(); + return true; + } + + // Get the first argument as a feature flag + string featureName = args[0]; + + // Get the associated feature + var topLevel = GetTopLevel(featureName); + if (topLevel == null || topLevel is not Feature feature) + { + Console.WriteLine($"'{featureName}' is not valid feature flag"); + OutputFeatureHelp(featureName); + return false; + } + + // Now verify that all other flags are valid + if (!feature.ProcessArgs(args, 1)) + return false; + + // If inputs are required + if (feature.RequiresInputs && !feature.VerifyInputs()) + { + OutputFeatureHelp(topLevel.Name); + return false; + } + + // Now execute the current feature + if (!feature.Execute()) + { + Console.Error.WriteLine("An error occurred during processing!"); + OutputFeatureHelp(topLevel.Name); + return false; + } + + return true; + } + + #endregion } }