Skip to content

Commit cc6babc

Browse files
authored
Merge pull request #503 from DiscoPYF/502-errorEnumGenerator
Create enum generator for ArangoDBErrors and generate change for ArangoDB 3.12
2 parents ce1deee + 18ac3e1 commit cc6babc

File tree

5 files changed

+962
-706
lines changed

5 files changed

+962
-706
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

ErrorEnumGenerator/Program.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.Text;
2+
using System.Text.RegularExpressions;
3+
4+
if (args.Length == 0)
5+
{
6+
Console.WriteLine("Please provide a file path as an argument.");
7+
Console.WriteLine("Usage: ErrorEnumGenerator.exe <error_codes_file> [output_folder]");
8+
Environment.Exit(1);
9+
}
10+
11+
string filePath = args[0];
12+
string outputFolder = args.Length > 1 ? args[1] : Directory.GetCurrentDirectory();
13+
14+
if (!File.Exists(filePath))
15+
{
16+
Console.WriteLine($"File not found: {filePath}");
17+
Environment.Exit(1);
18+
}
19+
20+
string fileContent = File.ReadAllText(filePath);
21+
22+
if (fileContent.Length == 0)
23+
{
24+
Console.WriteLine("File is empty.");
25+
Environment.Exit(1);
26+
}
27+
28+
var enumBuilder = new StringBuilder();
29+
30+
enumBuilder.AppendLine("// This file is generated by a tool.");
31+
enumBuilder.AppendLine();
32+
33+
enumBuilder.AppendLine("namespace ArangoDBNetStandard");
34+
enumBuilder.AppendLine("{");
35+
enumBuilder.AppendLine(" /// <summary>");
36+
enumBuilder.AppendLine(" /// ArangoDB error codes and their meanings.");
37+
enumBuilder.AppendLine(" /// </summary>");
38+
enumBuilder.AppendLine(" public enum ArangoDBErrors");
39+
enumBuilder.AppendLine(" {");
40+
41+
var regex = new Regex(@"^(\d+) - (\w+)\s*(.*)$", RegexOptions.Multiline);
42+
43+
var matches = regex.Matches(fileContent);
44+
45+
foreach (Match match in matches)
46+
{
47+
if (!match.Success)
48+
{
49+
Console.WriteLine($"Invalid format: {match.Value}");
50+
continue;
51+
}
52+
53+
string enumValue = match.Groups[1].Value.Trim();
54+
string enumName = match.Groups[2].Value.Trim();
55+
string enumSummary = match.Groups[3].Value.Trim();
56+
57+
enumBuilder.AppendLine(" /// <summary>");
58+
enumBuilder.AppendLine($" /// {enumSummary}");
59+
enumBuilder.AppendLine(" /// </summary>");
60+
enumBuilder.AppendLine($" {enumName} = {enumValue},");
61+
}
62+
63+
enumBuilder.AppendLine(" }");
64+
enumBuilder.AppendLine("}");
65+
66+
string outputFilePath = Path.Combine(outputFolder, "ArangoDBErrors.cs");
67+
File.WriteAllText(outputFilePath, enumBuilder.ToString());
68+
69+
Console.WriteLine($"Enum generated successfully at {outputFilePath}.");

arangodb-net-standard.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArangoDBNetStandard", "aran
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArangoDBNetStandardTest", "arangodb-net-standard.Test\ArangoDBNetStandardTest.csproj", "{70184444-F45A-4357-84BE-1AA5F6E8344E}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utilities", "Utilities", "{2B60E0F6-C6B4-4172-8E39-3310E33594A5}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ErrorEnumGenerator", "ErrorEnumGenerator\ErrorEnumGenerator.csproj", "{D9863444-75DE-4C54-A9B0-9F817CE3B119}"
13+
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1216
Debug|Any CPU = Debug|Any CPU
@@ -21,10 +25,17 @@ Global
2125
{70184444-F45A-4357-84BE-1AA5F6E8344E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2226
{70184444-F45A-4357-84BE-1AA5F6E8344E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2327
{70184444-F45A-4357-84BE-1AA5F6E8344E}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{D9863444-75DE-4C54-A9B0-9F817CE3B119}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{D9863444-75DE-4C54-A9B0-9F817CE3B119}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{D9863444-75DE-4C54-A9B0-9F817CE3B119}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{D9863444-75DE-4C54-A9B0-9F817CE3B119}.Release|Any CPU.Build.0 = Release|Any CPU
2432
EndGlobalSection
2533
GlobalSection(SolutionProperties) = preSolution
2634
HideSolutionNode = FALSE
2735
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{D9863444-75DE-4C54-A9B0-9F817CE3B119} = {2B60E0F6-C6B4-4172-8E39-3310E33594A5}
38+
EndGlobalSection
2839
GlobalSection(ExtensibilityGlobals) = postSolution
2940
SolutionGuid = {372F4FE3-7226-4A25-920F-43E06A2DE205}
3041
EndGlobalSection

0 commit comments

Comments
 (0)