-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added kpm_update.rs with working tests (#1040)
* fixed tests and added kpm_update Signed-off-by: d4v1d03 <[email protected]> * code formatting made better Signed-off-by: d4v1d03 <[email protected]> * make fmt done Signed-off-by: d4v1d03 <[email protected]> * removed kpm() Signed-off-by: d4v1d03 <[email protected]> * tweaks Signed-off-by: d4v1d03 <[email protected]> * re Signed-off-by: d4v1d03 <[email protected]> * removed unnecessary test that required test environment setup Signed-off-by: d4v1d03 <[email protected]> * fixed the failing test Signed-off-by: d4v1d03 <[email protected]> * removed Signed-off-by: d4v1d03 <[email protected]> * re Signed-off-by: d4v1d03 <[email protected]> * fix Signed-off-by: d4v1d03 <[email protected]> --------- Signed-off-by: d4v1d03 <[email protected]>
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::kpm_metadata::get_path_for_executable; | ||
use anyhow::{bail, Result}; | ||
use std::{path::PathBuf, process::Command}; | ||
|
||
const MANIFEST_FILE: &str = "kcl.mod"; | ||
|
||
pub(crate) fn update_kcl_module(manifest_path: PathBuf) -> Result<()> { | ||
match lookup_the_nearest_file_dir(manifest_path.clone(), MANIFEST_FILE) { | ||
Some(mod_dir) => { | ||
match Command::new(kcl()) | ||
.arg("mod") | ||
.arg("update") | ||
.current_dir(mod_dir) | ||
.output() | ||
{ | ||
Ok(output) => { | ||
if !output.status.success() { | ||
bail!( | ||
"update failed with error: {}", | ||
String::from_utf8_lossy(&output.stderr) | ||
); | ||
} | ||
Ok(()) | ||
} | ||
Err(err) => bail!("update failed with error: {}", err), | ||
} | ||
} | ||
None => bail!( | ||
"Manifest file '{}' not found in directory hierarchy", | ||
MANIFEST_FILE | ||
), | ||
} | ||
} | ||
pub fn kcl() -> PathBuf { | ||
get_path_for_executable("kcl") | ||
} | ||
|
||
pub(crate) fn lookup_the_nearest_file_dir( | ||
from: PathBuf, | ||
the_nearest_file: &str, | ||
) -> Option<PathBuf> { | ||
let mut current_dir = from; | ||
|
||
loop { | ||
let found_path = current_dir.join(the_nearest_file); | ||
if found_path.is_file() { | ||
return current_dir.canonicalize().ok(); | ||
} | ||
match current_dir.parent() { | ||
Some(parent) => current_dir = parent.to_path_buf(), | ||
None => return None, | ||
} | ||
} | ||
} |
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