teo_runtime/utils/
find_main_schema_file.rs1use teo_result::{Error, Result};
2use std::path::{Path, PathBuf};
3
4pub fn find_main_schema_file(file: Option<&str>, base_directory: &Path) -> Result<PathBuf> {
5 if let Some(file) = file {
6 let file_path = base_directory.join(file);
7 if file_path.is_file() {
8 return Ok(file_path);
9 } else {
10 return Err(Error::new(format!("cannot find schema file '{}'", file)));
11 }
12 }
13 let default = vec!["schema.teo", "index.teo", "src/schema.teo", "src/index.teo", "schema/index.teo", "src/schema/index.teo"];
14 for name in default {
15 let file_path = base_directory.join(name);
16 if file_path.is_file() {
17 return Ok(file_path);
18 }
19 }
20 Err(Error::new("cannot find default schema file"))
21}
22