pub fn cd(err_writer: &mut impl Write, argv: &[String]) -> BuiltinResult {
    let app = app_from_crate!()
        .name("cd")
        .about("change the current working directory")
        .arg(Arg::with_name("directory").help("the directory to change into"));

    let matches = handle_matches!(app, argv);

    let target = if matches.is_present("directory") {
        PathBuf::from(matches.value_of("directory").unwrap())
    } else {
        let dirs = match UserDirs::new() {
            Some(dirs) => dirs,
            None => {
                eprintln!("could not determine the home directory for the current user");

                return Err(WrashError::NonZeroExit(2));
            }
        };

        dirs.home_dir().to_path_buf()
    };

    if let Err(err) = std::env::set_current_dir(target) {
        writeln!(err_writer, "Error changing directory: {}", err)?;
        Err(WrashError::FailedIo(err))
    } else {
        Ok(())
    }
}
/// CD is builtin for changing the current working directory in the shell.
CD is builtin for changing the current working directory in the shell.
CD is builtin for changing the current working directory in the shell .
pub fn cd(err_writer: &mut impl Write, argv: &[String]) -> BuiltinResult {
    let app = app_from_crate!()
        .name("cd")
        .about("change the current working directory")
        .arg(Arg::with_name("directory").help("the directory to change into"));
    let matches = handle_matches!(app, argv);
    let target = if matches.is_present("directory") {
        PathBuf::from(matches.value_of("directory").unwrap())
    } else {
        let dirs = match UserDirs::new() {
            Some(dirs) => dirs,
            None => {
                eprintln!("could not determine the home directory for the current user");
                return Err(WrashError::NonZeroExit(2));
            }
        };
        dirs.home_dir().to_path_buf()
    };
    if let Err(err) = std::env::set_current_dir(target) {
        writeln!(err_writer, "Error changing directory: {}", err)?;
        Err(WrashError::FailedIo(err))
    } else {
        Ok(())
    }
}
pub fn cd ( err_writer : & mut impl Write , argv : & [ String ] ) -> BuiltinResult { let app = app_from_crate ! ( ) . name ( " " ) . about ( " " ) . arg ( Arg :: with_name ( " " ) . help ( " " ) ) ; let matches = handle_matches ! ( app argv ) ; let target = if matches . is_present ( " " ) { PathBuf :: from ( matches . value_of ( " " ) . unwrap ( ) ) } else { let dirs = match UserDirs :: new ( ) { Some ( dirs ) => dirs , None => { eprintln ! ( " " ) ; return Err ( WrashError :: NonZeroExit ( 2 ) ) ; } } ; dirs . home_dir ( ) . to_path_buf ( ) } ; if let Err ( err ) = std :: env :: set_current_dir ( target ) { writeln ! ( err_writer " " err ) ? ; Err ( WrashError :: FailedIo ( err ) ) } else { Ok ( ( ) ) } }
CD is builtin for changing the current working directory in the shell.
CD is builtin for changing the current working directory in the shell .
err_writer
&mut impl Write
argv
&[String]