-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2390 from fzyzcjy/feat/12627
- Loading branch information
Showing
6 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::command_run; | ||
use crate::library::commands::command_runner::call_shell; | ||
use std::path::Path; | ||
|
||
pub(crate) fn command_arg_maybe_fvm(pwd: Option<&Path>) -> Option<String> { | ||
if should_use_fvm(pwd) { | ||
Some("fvm".to_owned()) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
fn should_use_fvm(pwd: Option<&Path>) -> bool { | ||
if pwd.is_some() && !has_fvmrc(pwd.unwrap()) { | ||
false | ||
} else { | ||
let has_fvm_installation_output = has_fvm_installation(); | ||
if !has_fvm_installation_output { | ||
log::info!("Has .fvmrc but no fvm binary installation, thus skip using fvm."); | ||
} | ||
has_fvm_installation_output | ||
} | ||
} | ||
|
||
fn has_fvmrc(pwd: &Path) -> bool { | ||
let mut directory = pwd; | ||
loop { | ||
if directory.join(".fvmrc").exists() { | ||
return true; | ||
} | ||
if let Some(parent) = directory.parent() { | ||
directory = parent; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
fn has_fvm_installation() -> bool { | ||
command_run!(call_shell[None, None], "fvm", "--version") | ||
.map_or(false, |res| res.status.success()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters