using System; using System.Linq; using GeViSetEditor.Core.Parsers; using GeViSetEditor.Core.Models; using GeViSetEditor.CLI.Commands; namespace GeViSetEditor.CLI { class Program { static void Main(string[] args) { Console.WriteLine("=== GeViSet Configuration Editor ===\n"); if (args.Length == 0) { ShowHelp(); return; } string command = args[0].ToLower(); try { switch (command) { case "view": case "parse": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor view "); return; } ViewSetFile(args[1]); break; case "export": if (args.Length < 3) { Console.WriteLine("Usage: GeViSetEditor export "); return; } ExportToExcel(args[1], args[2]); break; case "import": if (args.Length < 3) { Console.WriteLine("Usage: GeViSetEditor import "); return; } ImportFromExcel(args[1], args[2]); break; case "test-roundtrip": case "test": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor test-roundtrip "); return; } TestRoundTripCommand.Execute(args[1]); break; case "parse-complete": case "full": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor parse-complete [output.json]"); return; } string jsonOutput = args.Length >= 3 ? args[2] : null; ParseCompleteCommand.Execute(args[1], jsonOutput); break; case "to-json": case "json": if (args.Length < 3) { Console.WriteLine("Usage: GeViSetEditor to-json "); return; } ExportJsonCommand.Execute(args[1], args[2]); break; case "enhanced": case "full-parse": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor enhanced [output.json]"); return; } string enhancedOutput = args.Length >= 3 ? args[2] : null; EnhancedParseCommand.Execute(args[1], enhancedOutput); break; case "analyze": case "inspect": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor analyze [report.json]"); return; } string reportOutput = args.Length >= 3 ? args[2] : null; AnalyzeStructureCommand.Execute(args[1], reportOutput); break; case "comprehensive": case "all": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor comprehensive [output.json]"); return; } string comprehensiveOutput = args.Length >= 3 ? args[2] : null; ComprehensiveParseCommand.Execute(args[1], comprehensiveOutput); break; case "modify": case "edit": if (args.Length < 2) { Console.WriteLine("Usage: GeViSetEditor modify [output.set]"); return; } string modifyOutput = args.Length >= 3 ? args[2] : null; ModifyConfigCommand.Execute(args[1], modifyOutput); break; default: Console.WriteLine($"Unknown command: {command}"); ShowHelp(); break; } } catch (Exception ex) { Console.WriteLine($"\n❌ Error: {ex.Message}"); Console.WriteLine($"\nStack trace:\n{ex.StackTrace}"); } } static void ShowHelp() { Console.WriteLine("Commands:"); Console.WriteLine(" view - View configuration and action mappings"); Console.WriteLine(" test-roundtrip - Test read/write safety (IMPORTANT!)"); Console.WriteLine(" comprehensive [out.json] - Parse ALL config data (19K+ nodes)"); Console.WriteLine(" modify [output.set] - Test edit/add/delete operations"); Console.WriteLine(" to-json - Export action mappings to JSON"); Console.WriteLine(" export - Export to Excel for editing"); Console.WriteLine(" import - Import from Excel to .set file"); Console.WriteLine("\nExamples:"); Console.WriteLine(" GeViSetEditor test-roundtrip TestMKS.set"); Console.WriteLine(" GeViSetEditor enhanced TestMKS.set full_config.json"); Console.WriteLine(" GeViSetEditor to-json TestMKS.set mappings.json"); Console.WriteLine(" GeViSetEditor view TestMKS.set"); Console.WriteLine(" GeViSetEditor export TestMKS.set mappings.xlsx"); } static void ViewSetFile(string inputPath) { Console.WriteLine($"Parsing: {inputPath}\n"); var parser = new SetFileParser(); var config = parser.Parse(inputPath); Console.WriteLine("\n" + new string('=', 70)); Console.WriteLine("CONFIGURATION SUMMARY"); Console.WriteLine(new string('=', 70) + "\n"); int totalRules = 0; int totalVariations = 0; foreach (var section in config.Sections) { if (section.Rules.Count > 0) { Console.WriteLine($"\n{section.Name}:"); Console.WriteLine(new string('-', 50)); foreach (var rule in section.Rules) { totalRules++; totalVariations += rule.ActionVariations.Count; Console.WriteLine($"\n Rule #{rule.RuleId}:"); // Show triggers var activeTriggers = rule.TriggerProperties.Where(kv => kv.Value).ToList(); if (activeTriggers.Any()) { Console.WriteLine($" Triggers: {string.Join(", ", activeTriggers.Select(t => t.Key))}"); } // Show main action if (!string.IsNullOrEmpty(rule.MainAction)) { Console.WriteLine($" Action: {rule.MainAction}"); } // Show variations if (rule.ActionVariations.Count > 0) { Console.WriteLine($" Variations ({rule.ActionVariations.Count}):"); foreach (var variation in rule.ActionVariations) { Console.WriteLine($" [{variation.VariationId}] {variation.ActionString}"); if (!string.IsNullOrEmpty(variation.ActionType)) { Console.WriteLine($" Type: {variation.ActionType}"); } if (!string.IsNullOrEmpty(variation.FullCommand)) { Console.WriteLine($" Command: {variation.FullCommand}"); } if (!string.IsNullOrEmpty(variation.ServerName)) { Console.WriteLine($" Server: {variation.ServerName}"); } } } } } } Console.WriteLine("\n" + new string('=', 70)); Console.WriteLine($"Total: {totalRules} rules, {totalVariations} variations"); Console.WriteLine(new string('=', 70)); } static void ExportToExcel(string inputPath, string outputPath) { Console.WriteLine("Excel export not yet implemented."); Console.WriteLine("Will be added in next step with EPPlus library."); } static void ImportFromExcel(string inputPath, string outputPath) { Console.WriteLine("Excel import not yet implemented."); Console.WriteLine("Will be added after export functionality."); } } }