90 lines
2.2 KiB
C#
90 lines
2.2 KiB
C#
using XSDVisualiser.Core;
|
|
using XSDVisualiser.Utils;
|
|
|
|
/*
|
|
if (args.Length == 0 || args[0] is "-h" or "--help")
|
|
{
|
|
PrintHelp();
|
|
return;
|
|
}
|
|
var inputPath = args[0];
|
|
*/
|
|
|
|
const string inputPath = "/home/frederik/Work/XSDVisualiser/XSDVisualiser/Rescources/SF2900/SF2900_EP_MS1-2/DistributionServiceMsgV2.xsd";
|
|
|
|
if (!File.Exists(inputPath))
|
|
{
|
|
Console.Error.WriteLine($"Input XSD file not found: {inputPath}");
|
|
Environment.Exit(1);
|
|
}
|
|
|
|
var format = "json";
|
|
string? outPath = null;
|
|
for (int i = 1; i < args.Length; i++)
|
|
{
|
|
switch (args[i])
|
|
{
|
|
case "--format":
|
|
if (i + 1 < args.Length)
|
|
{
|
|
format = args[++i].ToLowerInvariant();
|
|
}
|
|
else
|
|
{
|
|
Console.Error.WriteLine("--format requires a value: xml or json");
|
|
Environment.Exit(2);
|
|
}
|
|
break;
|
|
case "--out":
|
|
if (i + 1 < args.Length)
|
|
{
|
|
outPath = args[++i];
|
|
}
|
|
else
|
|
{
|
|
Console.Error.WriteLine("--out requires a file path");
|
|
Environment.Exit(2);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
var parser = new XsdSchemaParser();
|
|
var model = parser.Parse(inputPath);
|
|
|
|
string output = format switch
|
|
{
|
|
"json" => Serialization.ToJson(model),
|
|
_ => Serialization.ToXml(model)
|
|
};
|
|
|
|
if (!string.IsNullOrWhiteSpace(outPath))
|
|
{
|
|
File.WriteAllText(outPath!, output);
|
|
Console.WriteLine($"Wrote {format.ToUpperInvariant()} to {Path.GetFullPath(outPath!)}");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine(output);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine("Error: " + ex.ToString());
|
|
if (ex.InnerException != null)
|
|
{
|
|
Console.Error.WriteLine("Inner: " + ex.InnerException.ToString());
|
|
}
|
|
Environment.Exit(3);
|
|
}
|
|
|
|
return;
|
|
|
|
static void PrintHelp()
|
|
{
|
|
Console.WriteLine("XSDVisualiser - Parse an XSD and emit a structural model with types, constraints, and cardinality");
|
|
Console.WriteLine("Usage: XSDVisualiser <schema.xsd> [--format xml|json] [--out outputFile]");
|
|
Console.WriteLine("Default format is xml; if --out is omitted the output is printed to stdout.");
|
|
} |