style: 🔊 Add source instructions at the end of the log

This commit is contained in:
Sergio Gasquez 2023-01-16 11:04:04 +00:00 committed by Sergio Gasquez Arcos
parent ff602950bf
commit edded91b9f

View File

@ -272,11 +272,11 @@ async fn install(args: InstallOpts) -> Result<()> {
clear_dist_folder()?; clear_dist_folder()?;
} }
export_environment(&export_file, &exports)?; create_export_file(&export_file, &exports)?;
let config = Config { let config = Config {
esp_idf_version: args.esp_idf_version, esp_idf_version: args.esp_idf_version,
export_file: Some(export_file), export_file: Some(export_file.clone()),
extra_crates: extra_crates.as_ref().map(|extra_crates| { extra_crates: extra_crates.as_ref().map(|extra_crates| {
extra_crates extra_crates
.iter() .iter()
@ -298,10 +298,7 @@ async fn install(args: InstallOpts) -> Result<()> {
config_file.save()?; config_file.save()?;
info!("{} Installation successfully completed!", emoji::CHECK); info!("{} Installation successfully completed!", emoji::CHECK);
warn!( export_environment(&export_file)?;
"{} Please, source the export file, as stated above, to properly setup the environment!",
emoji::WARN
);
Ok(()) Ok(())
} }
@ -479,7 +476,7 @@ fn get_export_file(export_file: Option<PathBuf>) -> Result<PathBuf, Error> {
} }
/// Creates the export file with the necessary environment variables. /// Creates the export file with the necessary environment variables.
fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<(), Error> { fn create_export_file(export_file: &PathBuf, exports: &[String]) -> Result<(), Error> {
info!("{} Creating export file", emoji::WRENCH); info!("{} Creating export file", emoji::WRENCH);
let mut file = File::create(export_file)?; let mut file = File::create(export_file)?;
for e in exports.iter() { for e in exports.iter() {
@ -488,6 +485,12 @@ fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<(), E
file.write_all(e.as_bytes())?; file.write_all(e.as_bytes())?;
file.write_all(b"\n")?; file.write_all(b"\n")?;
} }
Ok(())
}
/// Instructions to export the environment variables.
fn export_environment(export_file: &PathBuf) -> Result<(), Error> {
#[cfg(windows)] #[cfg(windows)]
warn!( warn!(
"{} PLEASE set up the environment variables running: '{}'", "{} PLEASE set up the environment variables running: '{}'",
@ -504,6 +507,7 @@ fn export_environment(export_file: &PathBuf, exports: &[String]) -> Result<(), E
"{} This step must be done every time you open a new terminal.", "{} This step must be done every time you open a new terminal.",
emoji::WARN emoji::WARN
); );
Ok(()) Ok(())
} }
@ -527,7 +531,7 @@ pub fn check_arguments(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{export_environment, get_export_file, DEFAULT_EXPORT_FILE}; use crate::{create_export_file, get_export_file, DEFAULT_EXPORT_FILE};
use directories::BaseDirs; use directories::BaseDirs;
use std::{env::current_dir, path::PathBuf}; use std::{env::current_dir, path::PathBuf};
@ -556,7 +560,7 @@ mod tests {
} }
#[test] #[test]
fn test_export_environment() { fn test_create_export_file() {
// Creates the export file and writes the correct content to it // Creates the export file and writes the correct content to it
let temp_dir = tempfile::TempDir::new().unwrap(); let temp_dir = tempfile::TempDir::new().unwrap();
let export_file = temp_dir.path().join("export.sh"); let export_file = temp_dir.path().join("export.sh");
@ -564,7 +568,7 @@ mod tests {
"export VAR1=value1".to_string(), "export VAR1=value1".to_string(),
"export VAR2=value2".to_string(), "export VAR2=value2".to_string(),
]; ];
export_environment(&export_file, &exports).unwrap(); create_export_file(&export_file, &exports).unwrap();
let contents = std::fs::read_to_string(export_file).unwrap(); let contents = std::fs::read_to_string(export_file).unwrap();
assert_eq!(contents, "export VAR1=value1\nexport VAR2=value2\n"); assert_eq!(contents, "export VAR1=value1\nexport VAR2=value2\n");
@ -576,6 +580,6 @@ mod tests {
"export VAR1=value1".to_string(), "export VAR1=value1".to_string(),
"export VAR2=value2".to_string(), "export VAR2=value2".to_string(),
]; ];
assert!(export_environment(&export_file, &exports).is_err()); assert!(create_export_file(&export_file, &exports).is_err());
} }
} }