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;
|
||||||
use std::{env::set_current_dir, path::PathBuf};
|
use std::{env::set_current_dir, path::PathBuf};
|
||||||
|
@ -17,16 +18,16 @@ pub(super) fn cd(args: &Vec<String>) -> ExitCode {
|
||||||
|
|
||||||
let exit_code: ExitCode;
|
let exit_code: ExitCode;
|
||||||
if path.is_some() {
|
if path.is_some() {
|
||||||
exit_code = match set_current_dir(path.unwrap()) {
|
let result = set_current_dir(path.unwrap());
|
||||||
Ok(()) => ExitCode::success(),
|
|
||||||
Err(_e) => ExitCode::new(2),
|
if result.is_err() {
|
||||||
};
|
print_error("cd: no such file or directory");
|
||||||
|
exit_code = ExitCode::new(2);
|
||||||
} else {
|
} else {
|
||||||
exit_code = ExitCode::success();
|
exit_code = ExitCode::success();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if exit_code.get() != 0 {
|
exit_code = ExitCode::success();
|
||||||
print_error("lol");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_code
|
exit_code
|
||||||
|
|
Loading…
Reference in a new issue