TODO: refactor to reduce complexity
(
cli_mode: bool,
project_name: String,
database: Option<BackendDatabase>,
framework: Option<BackendFramework>,
plugins: Option<Vec<String>>,
)
| 221 | |
| 222 | #[allow(clippy::too_many_lines, clippy::cognitive_complexity)] //TODO: refactor to reduce complexity |
| 223 | fn create_project( |
| 224 | cli_mode: bool, |
| 225 | project_name: String, |
| 226 | database: Option<BackendDatabase>, |
| 227 | framework: Option<BackendFramework>, |
| 228 | plugins: Option<Vec<String>>, |
| 229 | ) -> anyhow::Result<()> { |
| 230 | // if we try making a project in an existing directory, throw an error |
| 231 | if PathBuf::from(&project_name).exists() { |
| 232 | logger::error(&format!( |
| 233 | "Cannot create a project: {:#?} already exists.", |
| 234 | PathBuf::from(&project_name) |
| 235 | )); |
| 236 | return Ok(()); |
| 237 | } |
| 238 | |
| 239 | // get the backend database |
| 240 | let backend_database = if let Some(database) = database { |
| 241 | database |
| 242 | } else { |
| 243 | assert!(!cli_mode, "Fatal: No backend database specified"); |
| 244 | logger::message("Select a database to use:"); |
| 245 | logger::message("Use UP/DOWN arrows to navigate and SPACE or ENTER to confirm."); |
| 246 | let items = vec!["postgres", "sqlite"]; |
| 247 | let selection = Select::with_theme(&ColorfulTheme::default()) |
| 248 | .items(&items) |
| 249 | .default(0) |
| 250 | .interact_on_opt(&Term::stderr())?; |
| 251 | |
| 252 | match selection { |
| 253 | Some(0) => BackendDatabase::Postgres, |
| 254 | Some(1) => BackendDatabase::Sqlite, |
| 255 | _ => panic!("Fatal: Unknown backend database specified."), |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | // get the backend database url |
| 260 | let backend_database_url: String = if cli_mode { |
| 261 | "postgres://postgres:postgres@localhost/database".to_string() |
| 262 | } else { |
| 263 | println!("Press Enter will use default backend database url as config"); |
| 264 | |
| 265 | Input::new() |
| 266 | .with_prompt(format!("{backend_database:?} url")) |
| 267 | .default("postgres://postgres:postgres@localhost/database".into()) |
| 268 | .show_default(false) |
| 269 | .interact_text()? |
| 270 | }; |
| 271 | |
| 272 | // get the backend framework |
| 273 | let backend_framework: BackendFramework = if let Some(framework) = framework { |
| 274 | framework |
| 275 | } else { |
| 276 | assert!(!cli_mode, "Fatal: No backend database specified"); |
| 277 | logger::message("Select a rust backend framework to use:"); |
| 278 | logger::message("Use UP/DOWN arrows to navigate and SPACE or ENTER to confirm."); |
| 279 | let items = vec!["actix-web", "poem"]; |
| 280 | let selection = Select::with_theme(&ColorfulTheme::default()) |
no test coverage detected