pub fn rename_peer(
    peers: &[Peer],
    args: &RenamePeerOpts,
) -> Result<Option<(PeerContents, Hostname)>, Error> {
    let eligible_peers = peers
        .iter()
        .filter(|p| &*p.name != "innernet-server")
        .collect::<Vec<_>>();
    let old_peer = if let Some(ref name) = args.name {
        eligible_peers
            .into_iter()
            .find(|p| &p.name == name)
            .ok_or_else(|| anyhow!("Peer '{}' does not exist", name))?
            .clone()
    } else {
        let (peer_index, _) = select(
            "Peer to rename",
            &eligible_peers
                .iter()
                .map(|ep| ep.name.clone())
                .collect::<Vec<_>>(),
        )?;
        eligible_peers[peer_index].clone()
    };
    let old_name = old_peer.name.clone();
    let new_name = if let Some(ref name) = args.new_name {
        name.clone()
    } else {
        input("New Name", Prefill::None)?
    };

    let mut new_peer = old_peer;
    new_peer.contents.name = new_name.clone();

    Ok(
        if args.yes
            || confirm(&format!(
                "Rename peer {} to {}?",
                old_name.yellow(),
                new_name.yellow()
            ))?
        {
            Some((new_peer.contents, old_name))
        } else {
            None
        },
    )
}
/// Bring up a prompt to create a new peer. Returns the peer request.
Bring up a prompt to create a new peer. Returns the peer request.
Bring up a prompt to create a new peer . Returns the peer request .
pub fn rename_peer(
    peers: &[Peer],
    args: &RenamePeerOpts,
) -> Result<Option<(PeerContents, Hostname)>, Error> {
    let eligible_peers = peers
        .iter()
        .filter(|p| &*p.name != "innernet-server")
        .collect::<Vec<_>>();
    let old_peer = if let Some(ref name) = args.name {
        eligible_peers
            .into_iter()
            .find(|p| &p.name == name)
            .ok_or_else(|| anyhow!("Peer '{}' does not exist", name))?
            .clone()
    } else {
        let (peer_index, _) = select(
            "Peer to rename",
            &eligible_peers
                .iter()
                .map(|ep| ep.name.clone())
                .collect::<Vec<_>>(),
        )?;
        eligible_peers[peer_index].clone()
    };
    let old_name = old_peer.name.clone();
    let new_name = if let Some(ref name) = args.new_name {
        name.clone()
    } else {
        input("New Name", Prefill::None)?
    };
    let mut new_peer = old_peer;
    new_peer.contents.name = new_name.clone();
    Ok(
        if args.yes
            || confirm(&format!(
                "Rename peer {} to {}?",
                old_name.yellow(),
                new_name.yellow()
            ))?
        {
            Some((new_peer.contents, old_name))
        } else {
            None
        },
    )
}
pub fn rename_peer ( peers : & [ Peer ] , args : & RenamePeerOpts , ) -> Result < Option < ( PeerContents , Hostname ) > , Error > { let eligible_peers = peers . iter ( ) . filter ( | p | & * p . name != " " ) . collect :: < Vec < _ > > ( ) ; let old_peer = if let Some ( ref name ) = args . name { eligible_peers . into_iter ( ) . find ( | p | & p . name == name ) . ok_or_else ( | | anyhow ! ( " " name ) ) ? . clone ( ) } else { let ( peer_index , _ ) = select ( " " , & eligible_peers . iter ( ) . map ( | ep | ep . name . clone ( ) ) . collect :: < Vec < _ > > ( ) , ) ? ; eligible_peers [ peer_index ] . clone ( ) } ; let old_name = old_peer . name . clone ( ) ; let new_name = if let Some ( ref name ) = args . new_name { name . clone ( ) } else { input ( " " , Prefill :: None ) ? } ; let mut new_peer = old_peer ; new_peer . contents . name = new_name . clone ( ) ; Ok ( if args . yes || confirm ( & format ! ( " " old_name yellow ( ) new_name yellow ( ) ) ) ? { Some ( ( new_peer . contents , old_name ) ) } else { None } , ) }
Bring up a prompt to create a new peer.
Bring up a prompt to create a new peer .
peers
&[Peer]
args
&RenamePeerOpts