async fn process_tree_command(
    safe: &mut Safe,
    target: Option<XorUrl>,
    details: bool,
    output_fmt: OutputFmt,
) -> Result<()> {
    let target_url = get_from_arg_or_stdin(target, Some("...awaiting target URl from STDIN"))?;

    debug!("Getting files in container {:?}", target_url);
    let files_map = match safe.fetch(&target_url, None).await? {
        SafeData::FilesContainer { files_map, .. } => files_map,
        _other_type => bail!("Make sure the URL targets a FilesContainer"),
    };

    // Create a top/root node representing `target_url`.
    let mut top = FileTreeNode::new(
        &target_url,
        FileTreeNodeType::Directory,
        FileDetails::default(),
    );
    // Transform flat list in `files_map` to a hierarchy in `top`
    let mut files: u64 = 0;
    let mut dirs: u64 = 0;
    for (name, file_details) in files_map.iter() {
        let path_parts: Vec<String> = name
            .to_string()
            .trim_matches('/')
            .split('/')
            .map(|s| s.to_string())
            .collect();
        let (d, f) = build_tree(&mut top, &path_parts, file_details, 0);
        files += f;
        dirs += d;
    }
    // Display.  with or without details.
    if OutputFmt::Pretty == output_fmt {
        if details {
            print_file_system_node_details(&top, dirs, files);
        } else {
            print_file_system_node(&top, dirs, files);
        }
    } else {
        println!("{}", serialise_output(&top, output_fmt));
    }

    Ok(())
}
// processes the `safe files tree` command.
processes the `safe files tree` command.
processes the ` safe files tree ` command .
async fn process_tree_command(
    safe: &mut Safe,
    target: Option<XorUrl>,
    details: bool,
    output_fmt: OutputFmt,
) -> Result<()> {
    let target_url = get_from_arg_or_stdin(target, Some("...awaiting target URl from STDIN"))?;
    debug!("Getting files in container {:?}", target_url);
    let files_map = match safe.fetch(&target_url, None).await? {
        SafeData::FilesContainer { files_map, .. } => files_map,
        _other_type => bail!("Make sure the URL targets a FilesContainer"),
    };
    // Create a top/root node representing `target_url`.
    let mut top = FileTreeNode::new(
        &target_url,
        FileTreeNodeType::Directory,
        FileDetails::default(),
    );
    // Transform flat list in `files_map` to a hierarchy in `top`
    let mut files: u64 = 0;
    let mut dirs: u64 = 0;
    for (name, file_details) in files_map.iter() {
        let path_parts: Vec<String> = name
            .to_string()
            .trim_matches('/')
            .split('/')
            .map(|s| s.to_string())
            .collect();
        let (d, f) = build_tree(&mut top, &path_parts, file_details, 0);
        files += f;
        dirs += d;
    }
    // Display.  with or without details.
    if OutputFmt::Pretty == output_fmt {
        if details {
            print_file_system_node_details(&top, dirs, files);
        } else {
            print_file_system_node(&top, dirs, files);
        }
    } else {
        println!("{}", serialise_output(&top, output_fmt));
    }
    Ok(())
}
async fn process_tree_command ( safe : & mut Safe , target : Option < XorUrl > , details : bool , output_fmt : OutputFmt , ) -> Result < ( ) > { let target_url = get_from_arg_or_stdin ( target , Some ( " " ) ) ? ; debug ! ( " " target_url ) ; let files_map = match safe . fetch ( & target_url , None ) . await ? { SafeData :: FilesContainer { files_map , .. } => files_map , _other_type => bail ! ( " " ) , } ; // Create a top/root node representing `target_url`. let mut top = FileTreeNode :: new ( & target_url , FileTreeNodeType :: Directory , FileDetails :: default ( ) , ) ; // Transform flat list in `files_map` to a hierarchy in `top` let mut files : u64 = 0 ; let mut dirs : u64 = 0 ; for ( name , file_details ) in files_map . iter ( ) { let path_parts : Vec < String > = name . to_string ( ) . trim_matches ( '/' ) . split ( '/' ) . map ( | s | s . to_string ( ) ) . collect ( ) ; let ( d , f ) = build_tree ( & mut top , & path_parts , file_details , 0 ) ; files += f ; dirs += d ; } // Display.  with or without details. if OutputFmt :: Pretty == output_fmt { if details { print_file_system_node_details ( & top , dirs , files ) ; } else { print_file_system_node ( & top , dirs , files ) ; } } else { println ! ( " " serialise_output ( top output_fmt ) ) ; } Ok ( ( ) ) }
processes the `safe files tree` command.
processes the ` safe files tree ` command .
safe
&mut Safe
target
Option<XorUrl>
details
bool
output_fmt
OutputFmt
safe
&mut Safe
target
Option<XorUrl>
details
bool
output_fmt
OutputFmt