export_structural_catalog/
export_structural_catalog.rs1use std::env;
6use std::io::{self, BufWriter, Write};
7
8use ifc_schema::{write_direct_structural_catalog, write_structural_catalog, SchemaVersion};
9
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 let requested = env::args().nth(1).ok_or_else(|| {
12 io::Error::new(
13 io::ErrorKind::InvalidInput,
14 "usage: cargo run -p ifc-schema --example export_structural_catalog -- <ifc2x3|ifc4|ifc4x3> [--direct]",
15 )
16 })?;
17 let version = match requested.to_ascii_lowercase().as_str() {
18 "ifc2x3" | "ifc2x3_tc1" => SchemaVersion::Ifc2x3,
19 "ifc4" | "ifc4_add2_tc1" => SchemaVersion::Ifc4,
20 "ifc4x3" | "ifc4x3_add2" => SchemaVersion::Ifc4x3,
21 _ => {
22 return Err(io::Error::new(
23 io::ErrorKind::InvalidInput,
24 format!("unsupported bundled IFC release: {requested}"),
25 )
26 .into());
27 }
28 };
29
30 let direct = match env::args().nth(2).as_deref() {
31 None => false,
32 Some("--direct") => true,
33 Some(value) => {
34 return Err(io::Error::new(
35 io::ErrorKind::InvalidInput,
36 format!("unsupported export option: {value}"),
37 )
38 .into());
39 }
40 };
41 if env::args().nth(3).is_some() {
42 return Err(io::Error::new(io::ErrorKind::InvalidInput, "too many arguments").into());
43 }
44
45 let stdout = io::stdout();
46 let mut output = BufWriter::new(stdout.lock());
47 let summary = if direct {
48 write_direct_structural_catalog(version, &mut output)?
49 } else {
50 write_structural_catalog(version, &mut output)?
51 };
52 output.flush()?;
53 eprintln!(
54 "exported {} entities and {} types for {}",
55 summary.entity_rows,
56 summary.type_count,
57 version.release_id()
58 );
59 Ok(())
60}