wng_lib/
lib.rs

1#![forbid(unsafe_code)]
2
3pub mod config;
4pub use dirs::home_dir;
5pub mod create;
6pub mod deps;
7mod errors;
8pub use errors::*;
9pub mod build;
10use std::path::PathBuf;
11use std::fs;
12pub mod install;
13
14pub fn get_config_file(path: Option<&str>) -> String {
15    let home_dir = dirs::home_dir().unwrap();
16    let default = format!("{}/.wng.config", home_dir.to_str().unwrap());
17    path.map(|x| x.to_owned()).unwrap_or(default)
18}
19
20
21pub fn see_dir(dirname: &PathBuf, o: bool, tests: bool) -> Result<Vec<PathBuf>> {
22    let entries = fs::read_dir(dirname)?;
23    let mut toret: Vec<PathBuf> = vec![];
24
25    for entry in entries {
26        let entry = entry?;
27
28        if entry.path().is_dir() {
29            toret.extend(see_dir(&entry.path().to_owned(), o, tests)?);
30        } else if o {
31            if entry.path().extension().unwrap().to_str().unwrap() == "o" {
32                toret.push(entry.path().to_owned());
33            }
34        } else if tests {
35            if entry.path().extension().unwrap().to_str().unwrap() == "c" && !entry.path().to_str().unwrap().ends_with("main.c") {
36                toret.push(entry.path().to_owned());
37            }
38        } else {
39            if entry.path().extension().unwrap().to_str().unwrap() == "c" && !entry.path().to_str().unwrap().ends_with("tests.c") {
40                toret.push(entry.path().to_owned());
41            }
42        }
43    }
44
45    Ok(toret)
46}