Skip to content

Commit

Permalink
feat: make path with expand
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 10, 2021
1 parent 28293b6 commit 018de67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 4 additions & 6 deletions core_model/src/support/path_format.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use std::path::{Path, PathBuf};
use std::path::PathBuf;

pub fn expand(path: &Path) -> PathBuf {
let input = &path.display().to_string();
pub fn expand(path: &str) -> PathBuf {
let input = &PathBuf::from(path).display().to_string();
let path = shellexpand::tilde(input);
return PathBuf::from(path.to_string());
}

#[cfg(test)]
mod test {
use crate::support::path_format::expand;
use std::path::Path;

#[test]
fn format_path() {
let path = Path::new("~");
let string = expand(path);
let string = expand("~");
assert_ne!(string.display().to_string(), "~");
}
}
5 changes: 3 additions & 2 deletions core_model/src/support/url_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};

use url::Url;

use crate::support::path_format;
use crate::Settings;

pub fn json_filename_suffix(text: &str, suffix_str: Option<&str>) -> String {
Expand Down Expand Up @@ -67,13 +68,13 @@ pub fn uri_to_path(url: &str) -> PathBuf {
let uri_path = match Url::parse(url) {
Ok(url) => url,
Err(_e) => {
return PathBuf::from(url);
return path_format::expand(url);
}
};

let root = Path::new(Settings::root());
if uri_path.host().is_none() {
return PathBuf::from(url);
return path_format::expand(url);
}
let mut buf = root.join(PathBuf::from(uri_path.host().unwrap().to_string()));

Expand Down

0 comments on commit 018de67

Please sign in to comment.