@@ -4,17 +4,23 @@ import argparse
4
4
5
5
from bragi .parser import CompilationUnit
6
6
from bragi .cpp_generator import CodeGenerator as CppCodeGenerator
7
+ from bragi .wireshark_generator import CodeGenerator as WiresharkCodeGenerator
7
8
8
9
parser = argparse .ArgumentParser (prog = 'bragi' , description = 'Bragi IDL to C++ compiler' )
9
10
parser .add_argument ('input' , nargs = '+' , help = 'input file' , type = argparse .FileType ('r' ))
10
11
parser .add_argument ('-o' , '--output' , help = 'output file' , type = str )
11
- parser .add_argument ('-l' , '--lib' , nargs = 1 , help = 'C++ library to use' , choices = ['frigg' , 'stdc++' ], default = 'libc++' )
12
- parser .add_argument ('--protobuf' , help = 'Generate protobuf compatibilty methods (SerializeAsString/ParseFromArray)' , action = 'store_true' )
12
+ subparsers = parser .add_subparsers (required = True , dest = 'language' )
13
+
14
+ cpp_parser = subparsers .add_parser ('cpp' )
15
+ cpp_parser .add_argument ('-l' , '--lib' , nargs = 1 , help = 'C++ library to use' , choices = ['frigg' , 'stdc++' ], default = 'libc++' )
16
+ cpp_parser .add_argument ('--protobuf' , help = 'Generate protobuf compatibilty methods (SerializeAsString/ParseFromArray)' , action = 'store_true' )
17
+
18
+ ws_parser = subparsers .add_parser ('wireshark' )
19
+
13
20
args = parser .parse_args ()
14
21
15
22
inputs = []
16
23
output = args .output
17
- lib = args .lib [0 ]
18
24
19
25
for source in args .input :
20
26
code = source .read ()
@@ -23,7 +29,11 @@ for source in args.input:
23
29
unit .verify ()
24
30
inputs .append (unit )
25
31
26
- generator = CppCodeGenerator (inputs , lib , protobuf_compat = args .protobuf )
32
+ if (args .language == "cpp" ):
33
+ lib = args .lib [0 ]
34
+ generator = CppCodeGenerator (inputs , lib , protobuf_compat = args .protobuf )
35
+ else :
36
+ generator = WiresharkCodeGenerator (inputs )
27
37
28
38
with open (output , "w" ) as o :
29
39
o .write (generator .generate ())
0 commit comments