1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#![cfg_attr(feature = "nightly-testing", feature(plugin))] #![cfg_attr(feature = "nightly-testing", plugin(clippy))] extern crate inflector; #[macro_use] extern crate lazy_static; extern crate regex; extern crate serde; extern crate serde_json; extern crate hyper; #[macro_use] extern crate serde_derive; use std::fs::File; use std::io::BufReader; use std::path::Path; use botocore::Service as BotocoreService; use generator::generate_source; pub mod botocore; pub mod generator; mod serialization; mod util; const BOTOCORE_DIR: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/botocore/botocore/data/"); pub struct Service { pub name: String, protocol_date: String, } impl Service { pub fn new<S>(name: S, protocol_date: S) -> Self where S: Into<String> { Service { name: name.into(), protocol_date: protocol_date.into(), } } } pub fn generate(service: Service, output_path: &Path) -> i32 { let destination_path = output_path.join(format!("{}.rs", service.name)); let botocore_service_data_path = Path::new(BOTOCORE_DIR) .join(format!("{}/{}/service-2.json", service.name, service.protocol_date)); botocore_generate(botocore_service_data_path.as_path(), destination_path.as_path()); return 1; } fn botocore_generate(input_path: &Path, output_path: &Path) { let input_file = File::open(input_path).expect(&format!( "{:?} not found", input_path, )); let service_data_as_reader = BufReader::new(input_file); let service: BotocoreService = serde_json::from_reader(service_data_as_reader).expect(&format!( "Could not convert JSON in {:?} to Service", input_path, )); match generate_source(&service, output_path) { Ok(()) => {}, _ => panic!("Failed to write file at {:?}", output_path) } }