openbim-ifc-cli 0.4.0

The openbim-ifc command: validate, convert, inspect, query and edit IFC files (STEP, ifcXML and ifcZIP), and exchange their values as CSV, TSV or XLSX tables, from a shell or CI.
//! `openbim-ifc`: validate, convert, inspect and query IFC files from a shell or CI.
//!
//! A thin command layer over the `openbim-ifc` facade: every answer comes
//! from a facade call, and this crate only parses arguments, picks a codec
//! and formats the result. Nothing here interprets IFC on its own.
//!
//! # Exit codes
//!
//! | Code | Meaning |
//! | --- | --- |
//! | 0 | Success; for `validate` and `lint`, no findings that fail the run |
//! | 1 | `validate` or `lint` reported findings that fail the run |
//! | 2 | Usage error, unreadable file, parse error, or a typed refusal |
//! | 3 | `edit` or `import-table` refused a planned change; nothing written |
//!
//! A refusal (an undeclared or unbundled schema, a missing entity, an
//! entity that carries no property sets, a model a layout cannot carry) is
//! never turned into an empty or guessed answer: it is reported on stderr
//! with its kind and the run exits 2.
//!
//! # Module map
//!
//! | Module | Role |
//! | --- | --- |
//! | `cli` | The argument grammar (clap) |
//! | `error` | `CliError`: the refusal kinds and their exit code |
//! | `input` | Reading STEP or ifcXML, the declared release, entity lookup |
//! | `json` | A small JSON writer for the machine-readable outputs |
//! | `sarif` | SARIF 2.1.0 for `validate` and `lint` |
//! | `output` | Writing a model: the format a path implies, edits beside or over the input |
//! | `report` | The changes and refusals of `edit` and `import-table` |
//! | `validate`, `convert`, `info`, `psets`, `tree`, `lint`, `select`, `edit`, `convert_units` | One command each |
//! | `relations`, `materials`, `cost`, `schedule` | One read-only view each |
//! | `table` | `export-table` and `import-table` |

mod cli;
mod convert;
mod convert_units;
mod cost;
mod edit;
mod error;
mod info;
mod input;
mod json;
mod lint;
mod materials;
mod output;
mod psets;
mod relations;
mod report;
mod sarif;
mod schedule;
mod select;
mod table;
mod tree;
mod validate;

use std::io::Write;
use std::process::ExitCode;

use clap::Parser;

fn main() -> ExitCode {
    let cli = cli::Cli::parse();
    let stdout = std::io::stdout();
    let mut out = stdout.lock();
    let result = match cli.command {
        cli::Command::Validate(args) => validate::run(&args, &mut out),
        cli::Command::Convert(args) => convert::run(&args, &mut out),
        cli::Command::Info(args) => info::run(&args, &mut out),
        cli::Command::Psets(args) => psets::run(&args, &mut out),
        cli::Command::Tree(args) => tree::run(&args, &mut out),
        cli::Command::Lint(args) => lint::run(&args, &mut out),
        cli::Command::Select(args) => select::run(&args, &mut out),
        cli::Command::ConvertUnits(args) => convert_units::run(&args, &mut out),
        cli::Command::Edit(args) => edit::run(&args, &mut out),
        cli::Command::ExportTable(args) => table::run_export(&args, &mut out),
        cli::Command::ImportTable(args) => table::run_import(&args, &mut out),
        cli::Command::Relations(args) => relations::run(&args, &mut out),
        cli::Command::Materials(args) => materials::run(&args, &mut out),
        cli::Command::Cost(args) => cost::run(&args, &mut out),
        cli::Command::Schedule(args) => schedule::run(&args, &mut out),
    };
    let _ = out.flush();
    match result {
        Ok(outcome) => ExitCode::from(outcome.code()),
        Err(error) => {
            eprintln!("openbim-ifc: {error}");
            ExitCode::from(error.exit_code())
        }
    }
}