Skip to content

Commit

Permalink
feat: workspace (find .nvmdrc recursively from the current working …
Browse files Browse the repository at this point in the history
…directory)

Signed-off-by: The1111mp <The1111mp@outlook.com>
  • Loading branch information
1111mp committed Feb 25, 2024
1 parent 9fc6bb0 commit 23959ba
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/common.rs
Expand Up @@ -88,12 +88,7 @@ fn get_default_installtion_path() -> PathBuf {
}

fn get_version() -> String {
let mut nvmdrc = match env::current_dir() {
Err(_) => PathBuf::from(""),
Ok(dir) => dir,
};
nvmdrc.push(".nvmdrc");

let nvmdrc = find_nvmdrc();
let project_version = match read_to_string(&nvmdrc) {
Err(_) => String::from(""),
Ok(v) => v,
Expand All @@ -112,6 +107,24 @@ fn get_version() -> String {
}
}

fn find_nvmdrc() -> PathBuf {
let mut current_dir = match env::current_dir() {
Ok(dir) => dir,
Err(_) => PathBuf::from(""),
};
current_dir.push(".nvmdrc");

while current_dir.pop() {
let mut nvmdrc = current_dir.clone();
nvmdrc.push(".nvmdrc");
if nvmdrc.is_file() {
return nvmdrc;
}
}

PathBuf::from("")
}

fn get_nvmd_path() -> PathBuf {
match default_home_dir() {
Ok(p) => p,
Expand Down

0 comments on commit 23959ba

Please sign in to comment.