use std::{env::current_dir, path::PathBuf}; use mingling::{ Program, macros::{arg, program_setup}, picker::{PickerHelper, value::DirPath}, }; use crate::ThisProgram; #[derive(Default, Clone)] pub struct ResGodotProjectDirectory { pub dir: Option, } #[program_setup] pub fn godot_project_setup(p: &mut Program) { let dir = p .pick_argument(&arg![project: Option, 'P']) .unwrap(); if let Some(dir) = dir && dir.to_path_buf().join("project.godot").exists() { p.with_resource(ResGodotProjectDirectory { dir: Some(dir.to_path_buf()), }); return; } let mut cwd = current_dir().unwrap(); loop { if cwd.join("project.godot").exists() { p.with_resource(ResGodotProjectDirectory { dir: Some(cwd) }); return; } if !cwd.pop() { break; } } p.with_resource(ResGodotProjectDirectory { dir: None }); }