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 } .") ;
0 commit comments