use eyre::ContextCompat;
use std::path::Path;
mod c;
mod cxx;
mod python;
mod rust;
fn workspace_dir() -> eyre::Result<String> {
let dir = Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.context("Could not get manifest parent folder")?
.parent()
.context("Could not get manifest grandparent folder")?
.to_str()
.context("dora workspace path is not valid UTF-8")?;
Ok(normalize_for_cmake(dir))
}
fn normalize_for_cmake(path: &str) -> String {
path.replace('\\', "/")
}
pub fn create(args: crate::CommandNew, use_path_deps: bool) -> eyre::Result<()> {
match args.lang {
crate::Lang::Rust => rust::create(args, use_path_deps),
crate::Lang::Python => python::create(args, use_path_deps),
crate::Lang::C => c::create(args, use_path_deps),
crate::Lang::Cxx => cxx::create(args, use_path_deps),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn normalize_for_cmake_replaces_backslashes() {
let normalized = normalize_for_cmake(r"C:\Users\example\dora");
assert_eq!(normalized, "C:/Users/example/dora");
assert!(!normalized.contains('\\'));
}
}