forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.rs
More file actions
32 lines (26 loc) · 928 Bytes
/
Copy pathtree.rs
File metadata and controls
32 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use camino::Utf8PathBuf;
use driver::{DependencyTree, DriverDataBase, init_ingot};
use url::Url;
pub fn print_tree(path: &Utf8PathBuf) {
let ingot_url = match ingot_url(path) {
Ok(url) => url,
Err(message) => {
eprintln!("{message}");
return;
}
};
let mut db = DriverDataBase::default();
let _ = init_ingot(&mut db, &ingot_url);
let tree = DependencyTree::build(&db, &ingot_url);
print!("{}", tree.display());
}
fn ingot_url(path: &Utf8PathBuf) -> Result<Url, String> {
let canonical_path = path
.canonicalize_utf8()
.map_err(|_| format!("Error: invalid or non-existent directory path: {path}"))?;
if !canonical_path.is_dir() {
return Err(format!("Error: {path} is not a directory"));
}
Url::from_directory_path(canonical_path.as_str())
.map_err(|_| format!("Error: invalid directory path: {path}"))
}