builtins::cd : meilleur gestion des erreurs
This commit is contained in:
parent
abd857f0e4
commit
a16ed0e030
1 changed files with 10 additions and 9 deletions
|
@ -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,18 +18,18 @@ 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();
|
||||
}
|
||||
} else {
|
||||
exit_code = ExitCode::success();
|
||||
}
|
||||
|
||||
if exit_code.get() != 0 {
|
||||
print_error("lol");
|
||||
}
|
||||
|
||||
exit_code
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue