SessionZero.SzfToolkit-Dotnet/SessionZero.SzfCli/Program.cs
2025-07-21 21:59:01 -05:00

83 lines
3.5 KiB
C#

using Spectre.Console;
using SessionZero.SzfLib.Parser;
using System.IO;
using SessionZero.SzfLib.Helpers;
void PrintSection(dynamic section, int indent = 0)
{
string indentStr = new string(' ', indent * 2);
AnsiConsole.MarkupLine($"\n{indentStr}[bold yellow]Section:[/] {section.Name}");
if (section.Fields.Count == 0)
{
AnsiConsole.MarkupLine($"{indentStr}[italic]No fields[/]");
}
else
{
var table = new Table();
table.AddColumn("Field Name");
table.AddColumn("Type");
table.AddColumn("Value");
foreach (var field in section.Fields.Values)
{
var typedField = (SzfField)field;
table.AddRow(typedField.Name, typedField.SzfType.ToString(), typedField.Value ?? "");
}
AnsiConsole.Write(table);
}
if (section.Subsections.Count > 0)
{
AnsiConsole.MarkupLine($"{indentStr}[italic]Subsections:[/]");
foreach (var sub in section.Subsections.Values)
{
PrintSection(sub, indent + 1);
}
}
}
AnsiConsole.MarkupLine("[deepskyblue4_1]\n\n" +
" █████████ ███████████ ███████████ █████████ █████ █████\n" +
" ███░░░░░███░█░░░░░░███ ░░███░░░░░░█ ███░░░░░███░░███ ░░███ \n" +
"░███ ░░░ ░ ███░ ░███ █ ░ ███ ░░░ ░███ ░███ \n" +
"░░█████████ ███ ░███████ ░███ ░███ ░███ \n" +
" ░░░░░░░░███ ███ ░███░░░█ ░███ ░███ ░███ \n" +
" ███ ░███ ████ █ ░███ ░ ░░███ ███ ░███ █ ░███ \n" +
"░░█████████ ███████████ █████ ░░█████████ ███████████ █████\n" +
" ░░░░░░░░░ ░░░░░░░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░░ ░░░░░ \n\n[/]"
);
AnsiConsole.MarkupLine("[deepskyblue4_2]A tool for testing the SessionZero SZF Parser[/]");
var filePath = AnsiConsole.Ask<string>("Enter the path to the [green]SZF file[/]:");
if (!File.Exists(filePath))
{
AnsiConsole.MarkupLine("[red]File not found![/]");
return;
}
string szfContent = File.ReadAllText(filePath);
var parser = new SzfParser();
try
{
var szfObject = parser.Parse(szfContent);
if (szfObject == null)
{
AnsiConsole.MarkupLine("[red]Failed to parse SZF file.[/]");
return;
}
AnsiConsole.MarkupLine($"[bold]SZF Type:[/] {szfObject.SzfType}");
AnsiConsole.MarkupLine($"[bold]SZF Version:[/] {szfObject.SzfVersion}");
AnsiConsole.MarkupLine($"[bold]Number of Sections:[/] {szfObject.Sections.Count}");
foreach (var section in szfObject.Sections)
{
PrintSection(section);
}
}
catch (SzfError ex)
{
AnsiConsole.MarkupLine($"[bold][red]Szf Validation Error:[/][/]\r\n{ex.Message}");
}