1 use std::env;
2 use std::fs;
3 
4 use protobuf::text_format;
5 use protobuf_parse::Parser;
6 
7 enum Which {
8     Protoc,
9     Pure,
10 }
11 
main()12 fn main() {
13     let args = env::args().skip(1).collect::<Vec<_>>();
14     let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();
15     let (path, out_protoc, out_pure) = match args.as_slice() {
16         // Just invoke protoc.
17         [path, out_protoc, out_pure] => (path, out_protoc, out_pure),
18         _ => panic!("wrong args"),
19     };
20 
21     for which in [Which::Pure, Which::Protoc] {
22         let mut parser = Parser::new();
23         match which {
24             Which::Protoc => {
25                 parser.protoc();
26             }
27             Which::Pure => {
28                 parser.pure();
29             }
30         }
31 
32         parser.input(path);
33         parser.include(".");
34         let fds = parser.file_descriptor_set().unwrap();
35         let fds = text_format::print_to_string_pretty(&fds);
36         let out = match which {
37             Which::Protoc => out_protoc,
38             Which::Pure => out_pure,
39         };
40         fs::write(out, fds).unwrap();
41     }
42 }
43