builtins::cd : meilleur gestion des erreurs

This commit is contained in:
Ahurac 2024-04-16 16:08:15 +02:00
parent abd857f0e4
commit a16ed0e030

View file

@ -1,4 +1,5 @@
use crate::{error::print_error, exit_code::ExitCode};
use crate::error::print_error;
use crate::exit_code::ExitCode;
use std::env;
use std::{env::set_current_dir, path::PathBuf};
@ -17,16 +18,16 @@ pub(super) fn cd(args: &Vec<String>) -> ExitCode {
let exit_code: ExitCode;
if path.is_some() {
exit_code = match set_current_dir(path.unwrap()) {
Ok(()) => ExitCode::success(),
Err(_e) => ExitCode::new(2),
};
let result = set_current_dir(path.unwrap());
if result.is_err() {
print_error("cd: no such file or directory");
exit_code = ExitCode::new(2);
} else {
exit_code = ExitCode::success();
}
if exit_code.get() != 0 {
print_error("lol");
} else {
exit_code = ExitCode::success();
}
exit_code