Skip to content

Commit fec2de6

Browse files
committed
feat(Windows): support for windows filepaths
used cfg!() macro to check for windows before replacing ~
1 parent 984e546 commit fec2de6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/docs.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ fn generate_doc_file(docs: &[&str], fname: String, delims: Delimiters) -> DocFil
179179

180180
/// Given a file path and delimiters, generate a DocFile for all files requested.
181181
pub fn start(p: &str, is_directory: bool, delims: Delimiters) -> Vec<DocFile> {
182-
let dir = p.replace("~", home_dir().unwrap().to_str().unwrap());
182+
let dir = if cfg!(windows) {
183+
String::from(p)
184+
} else {
185+
p.replace("~", home_dir().unwrap().to_str().unwrap())
186+
};
183187
if is_directory {
184188
let files: Vec<_> = glob(&dir).unwrap().filter_map(|x| x.ok()).collect();
185189
let every_doc: Vec<DocFile> = files
@@ -292,7 +296,11 @@ pub fn printer(thedocs: &DocFile) {
292296
/// Given a list of `DocFile` and a file path, write the JSON representation to a file.
293297
pub fn to_json(docstrings: &[DocFile], file_name: &str) {
294298
let json = serde_json::to_string_pretty(&docstrings).expect("Could not convert to JSON");
295-
let path_as_str = file_name.replace("~", home_dir().unwrap().to_str().unwrap());
299+
let path_as_str = if cfg!(windows) {
300+
String::from(file_name)
301+
} else {
302+
file_name.replace("~", home_dir().unwrap().to_str().unwrap())
303+
};
296304
let path = Path::new(&path_as_str);
297305
let mut file = File::create(Path::new(&path)).expect("Invalid file path.");
298306
file.write_all(&json.as_bytes())

0 commit comments

Comments
 (0)