use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[command(
name = "openbim-ifc",
version,
about,
long_about = None,
after_help = "Exit codes: 0 success, 1 findings (validate, lint), 2 usage error, \
unreadable input or a refusal.\nGuide: https://openbimrs.github.io/ifc/guide/cli"
)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Command,
}
#[derive(Debug, Subcommand)]
pub(crate) enum Command {
Validate(ValidateArgs),
Convert(ConvertArgs),
Info(InfoArgs),
Psets(PsetsArgs),
Tree(TreeArgs),
Lint(LintArgs),
Select(SelectArgs),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum InputLayout {
Auto,
Native,
Xsd,
}
#[derive(Debug, Clone, Args)]
pub(crate) struct InputArgs {
#[arg(long, value_enum, default_value_t = InputLayout::Auto)]
pub(crate) input_layout: InputLayout,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum ReportFormat {
Human,
Json,
Sarif,
}
#[derive(Debug, Args)]
pub(crate) struct ValidateArgs {
#[arg(required = true)]
pub(crate) files: Vec<PathBuf>,
#[arg(long, value_enum, default_value_t = ReportFormat::Human)]
pub(crate) format: ReportFormat,
#[arg(long, value_name = "N")]
pub(crate) max_findings: Option<usize>,
#[arg(long)]
pub(crate) deny_warnings: bool,
#[arg(long)]
pub(crate) include_unsupported: bool,
#[command(flatten)]
pub(crate) input: InputArgs,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum ModelFormat {
Step,
Ifcxml,
Ifczip,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum InnerFormat {
Step,
Ifcxml,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum OutputLayout {
Native,
Xsd,
}
#[derive(Debug, Args)]
pub(crate) struct ConvertArgs {
pub(crate) input: PathBuf,
pub(crate) output: PathBuf,
#[arg(long, value_enum)]
pub(crate) to: Option<ModelFormat>,
#[arg(long, value_enum)]
pub(crate) inner: Option<InnerFormat>,
#[arg(long, value_enum)]
pub(crate) layout: Option<OutputLayout>,
#[arg(long)]
pub(crate) force: bool,
#[command(flatten)]
pub(crate) input_options: InputArgs,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum TextFormat {
Human,
Json,
}
#[derive(Debug, Args)]
pub(crate) struct InfoArgs {
pub(crate) file: PathBuf,
#[arg(long, value_enum, default_value_t = TextFormat::Human)]
pub(crate) format: TextFormat,
#[arg(long)]
pub(crate) all_types: bool,
#[command(flatten)]
pub(crate) input: InputArgs,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum TableFormat {
Table,
Json,
Csv,
}
#[derive(Debug, Args)]
pub(crate) struct PsetsArgs {
pub(crate) file: PathBuf,
pub(crate) entity: String,
#[arg(long, value_enum, default_value_t = TableFormat::Table)]
pub(crate) format: TableFormat,
#[command(flatten)]
pub(crate) input: InputArgs,
}
#[derive(Debug, Args)]
pub(crate) struct TreeArgs {
pub(crate) file: PathBuf,
#[arg(long, value_enum, default_value_t = TextFormat::Human)]
pub(crate) format: TextFormat,
#[arg(long)]
pub(crate) elements: bool,
#[command(flatten)]
pub(crate) input: InputArgs,
}
#[derive(Debug, Args)]
pub(crate) struct LintArgs {
#[arg(required = true)]
pub(crate) files: Vec<PathBuf>,
#[arg(long, value_enum, default_value_t = ReportFormat::Human)]
pub(crate) format: ReportFormat,
#[command(flatten)]
pub(crate) input: InputArgs,
}
#[derive(Debug, Args)]
pub(crate) struct SelectArgs {
pub(crate) file: PathBuf,
pub(crate) query: String,
#[arg(long = "value", value_name = "PATH")]
pub(crate) values: Vec<String>,
#[arg(long, value_enum, default_value_t = TableFormat::Table)]
pub(crate) format: TableFormat,
#[command(flatten)]
pub(crate) input: InputArgs,
}
#[cfg(test)]
mod tests {
use clap::CommandFactory;
#[test]
fn the_grammar_is_consistent() {
super::Cli::command().debug_assert();
}
}