pub fn enable_or_disable_peer(peers: &[Peer], enable: bool) -> Result<Option<Peer>, Error> {
    let enabled_peers: Vec<_> = peers
        .iter()
        .filter(|peer| enable && peer.is_disabled || !enable && !peer.is_disabled)
        .collect();

    let peer_selection: Vec<_> = enabled_peers
        .iter()
        .map(|peer| format!("{} ({})", &peer.name, &peer.ip))
        .collect();
    let (index, _) = select(
        &format!("Peer to {}able", if enable { "en" } else { "dis" }),
        &peer_selection,
    )?;
    let peer = enabled_peers[index];

    Ok(
        if confirm(&format!(
            "{}able peer {}?",
            if enable { "En" } else { "Dis" },
            peer.name.yellow()
        ))? {
            Some(peer.clone())
        } else {
            None
        },
    )
}
/// Presents a selection and confirmation of eligible peers for either disabling or enabling,
/// and returns back the ID of the selected peer.
Presents a selection and confirmation of eligible peers for either disabling or enabling,
and returns back the ID of the selected peer.
Presents a selection and confirmation of eligible peers for either disabling or enabling and returns back the ID of the selected peer .
pub fn enable_or_disable_peer(peers: &[Peer], enable: bool) -> Result<Option<Peer>, Error> {
    let enabled_peers: Vec<_> = peers
        .iter()
        .filter(|peer| enable && peer.is_disabled || !enable && !peer.is_disabled)
        .collect();
    let peer_selection: Vec<_> = enabled_peers
        .iter()
        .map(|peer| format!("{} ({})", &peer.name, &peer.ip))
        .collect();
    let (index, _) = select(
        &format!("Peer to {}able", if enable { "en" } else { "dis" }),
        &peer_selection,
    )?;
    let peer = enabled_peers[index];
    Ok(
        if confirm(&format!(
            "{}able peer {}?",
            if enable { "En" } else { "Dis" },
            peer.name.yellow()
        ))? {
            Some(peer.clone())
        } else {
            None
        },
    )
}
pub fn enable_or_disable_peer ( peers : & [ Peer ] , enable : bool ) -> Result < Option < Peer > , Error > { let enabled_peers : Vec < _ > = peers . iter ( ) . filter ( | peer | enable && peer . is_disabled || ! enable && ! peer . is_disabled ) . collect ( ) ; let peer_selection : Vec < _ > = enabled_peers . iter ( ) . map ( | peer | format ! ( " " peer name peer ip ) ) . collect ( ) ; let ( index , _ ) = select ( & format ! ( " " if enable { " " } else { " " } ) , & peer_selection , ) ? ; let peer = enabled_peers [ index ] ; Ok ( if confirm ( & format ! ( " " if enable { " " } else { " " } peer name yellow ( ) ) ) ? { Some ( peer . clone ( ) ) } else { None } , ) }
Presents a selection and confirmation of eligible peers for either disabling or enabling,
and returns back the ID of the selected peer.
Presents a selection and confirmation of eligible peers for either disabling or enabling and returns back the ID of the selected peer .
peers
&[Peer]
enable
bool