From fd364804e0c4ebff9fd704b74a3e7e22ca6eb749 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Sat, 3 Feb 2024 22:36:53 -0600 Subject: [PATCH] command-line interface for vst3-bindgen --- Cargo.toml | 1 + vst3-bindgen-cli/Cargo.toml | 16 ++++++++++++++ vst3-bindgen-cli/src/main.rs | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 vst3-bindgen-cli/Cargo.toml create mode 100644 vst3-bindgen-cli/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index d4c707ef..8271a1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,5 @@ members = [ "com-scrape", "com-scrape-types", "vst3-bindgen", + "vst3-bindgen-cli", ] diff --git a/vst3-bindgen-cli/Cargo.toml b/vst3-bindgen-cli/Cargo.toml new file mode 100644 index 00000000..2977f3e3 --- /dev/null +++ b/vst3-bindgen-cli/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "vst3-bindgen-cli" +version = "0.1.0" +authors = ["Micah Johnston "] +edition = "2021" +description = "Binding generator for the VST 3 API" +repository = "https://github.com/coupler-rs/vst3-rs" +license = "MIT OR Apache-2.0" + +[[bin]] +path = "src/main.rs" +name = "vst3-bindgen" + +[dependencies] +vst3-bindgen = { path = "../vst3-bindgen", version = "0.2.1" } +clap = { version = "3.1.17", features = ["derive", "cargo"] } diff --git a/vst3-bindgen-cli/src/main.rs b/vst3-bindgen-cli/src/main.rs new file mode 100644 index 00000000..8f701971 --- /dev/null +++ b/vst3-bindgen-cli/src/main.rs @@ -0,0 +1,43 @@ +use std::path::PathBuf; + +use std::error::Error; +use std::fs::File; +use std::io::{stdout, BufWriter, Write}; +use std::process; + +use clap::Parser; +use vst3_bindgen::generate; + +#[derive(Parser)] +struct Vst3Bindgen { + sdk_dir: PathBuf, + + #[clap(long, value_name = "TRIPLE")] + target: Option, + + #[clap(long, short, value_name = "OUTPUT")] + output: Option, +} + +fn vst3_bindgen(cmd: &Vst3Bindgen) -> Result<(), Box> { + let mut bindings = Vec::new(); + + generate(&cmd.sdk_dir, cmd.target.as_deref(), &mut bindings)?; + + if let Some(output) = &cmd.output { + let file = File::create(output)?; + BufWriter::new(file).write_all(&bindings)?; + } else { + BufWriter::new(stdout()).write_all(&bindings)?; + }; + + Ok(()) +} + +fn main() { + let cmd = Vst3Bindgen::parse(); + if let Err(err) = vst3_bindgen(&cmd) { + eprintln!("error: {}", err); + process::exit(1); + } +}