(project_name: &str, creation_options: CreationOptions)
| 281 | #[allow(clippy::too_many_lines)] //TODO: refactor to reduce complexity |
| 282 | #[allow(clippy::cognitive_complexity)] |
| 283 | pub fn create(project_name: &str, creation_options: CreationOptions) -> Result<()> { |
| 284 | /* |
| 285 | Temporary guard until we get poem supported again |
| 286 | */ |
| 287 | let cra_version = env!("CARGO_PKG_VERSION"); |
| 288 | if !cra_version.eq("9.2.2") && creation_options.backend_framework == BackendFramework::Poem { |
| 289 | logger::error("Poem is not supported in this version of create-rust-app. Please use version 9.2.2 (cargo install create-rust-app_cli@9.2.2). We hope to bring back poem-web as well as other frameworks in the future."); |
| 290 | std::process::exit(1); |
| 291 | } |
| 292 | |
| 293 | let mut project_dir: PathBuf = PathBuf::from(project_name); |
| 294 | |
| 295 | if project_dir.exists() { |
| 296 | logger::message("Directory already exists"); |
| 297 | |
| 298 | project_dir = match std::fs::canonicalize(project_dir) { |
| 299 | Ok(p) => p, |
| 300 | Err(err) => logger::exit_error("std::fs::canonicalize():", &err), |
| 301 | }; |
| 302 | |
| 303 | let proceed = !creation_options.cli_mode |
| 304 | && Confirm::with_theme(&ColorfulTheme::default()) |
| 305 | .with_prompt("Delete directory contents?") |
| 306 | .default(false) |
| 307 | .interact()?; |
| 308 | |
| 309 | if proceed { |
| 310 | match std::fs::remove_dir_all(&project_dir) { |
| 311 | Ok(()) => {} |
| 312 | Err(err) => logger::exit_error("std::fs::remove_dir_all():", &err), |
| 313 | } |
| 314 | } else { |
| 315 | std::process::exit(0); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | let project_name = project_dir |
| 320 | .components() |
| 321 | .last() |
| 322 | .unwrap() |
| 323 | .as_os_str() |
| 324 | .to_str() |
| 325 | .unwrap(); |
| 326 | |
| 327 | logger::message(&format!( |
| 328 | "Creating project {} with backend {}", |
| 329 | style(project_name).yellow(), |
| 330 | style(&format!("{:?}", creation_options.backend_framework)).yellow() |
| 331 | )); |
| 332 | |
| 333 | logger::message("Creating Project Directory"); |
| 334 | match std::fs::create_dir_all(&project_dir) { |
| 335 | Ok(()) => {} |
| 336 | Err(err) => logger::exit_error("std::fs::create_dir_all():", &err), |
| 337 | } |
| 338 | |
| 339 | logger::command_msg("cargo init"); |
| 340 |
no test coverage detected