embeddenator_cli/utils/
path.rs1use std::path::Path;
4
5pub fn path_to_forward_slash_string(path: &Path) -> String {
7 path.components()
8 .filter_map(|c| match c {
9 std::path::Component::Normal(s) => s.to_str().map(|v| v.to_string()),
10 _ => None,
11 })
12 .collect::<Vec<String>>()
13 .join("/")
14}
15
16pub fn logical_path_for_file_input(path: &Path, cwd: &Path) -> String {
22 if path.is_relative() {
23 return path_to_forward_slash_string(path);
24 }
25
26 if let Ok(rel) = path.strip_prefix(cwd) {
27 let s = path_to_forward_slash_string(rel);
28 if !s.is_empty() {
29 return s;
30 }
31 }
32
33 path.file_name()
34 .and_then(|s| s.to_str())
35 .unwrap_or("input.bin")
36 .to_string()
37}