pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result<Option<CidrContents>, Error> {
    let parent_cidr = if let Some(ref parent_name) = request.parent {
        cidrs
            .iter()
            .find(|cidr| &cidr.name == parent_name)
            .ok_or_else(|| anyhow!("No parent CIDR with that name exists."))?
    } else {
        choose_cidr(cidrs, "Parent CIDR")?
    };

    let name = if let Some(ref name) = request.name {
        name.clone()
    } else {
        input("Name", Prefill::None)?
    };

    let cidr = if let Some(cidr) = request.cidr {
        cidr
    } else {
        input("CIDR", Prefill::None)?
    };

    let cidr_request = CidrContents {
        name: name.to_string(),
        cidr,
        parent: Some(parent_cidr.id),
    };

    Ok(
        if request.yes || confirm(&format!("Create CIDR \"{}\"?", cidr_request.name))? {
            Some(cidr_request)
        } else {
            None
        },
    )
}
/// Bring up a prompt to create a new CIDR. Returns the peer request.
Bring up a prompt to create a new CIDR. Returns the peer request.
Bring up a prompt to create a new CIDR . Returns the peer request .
pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result<Option<CidrContents>, Error> {
    let parent_cidr = if let Some(ref parent_name) = request.parent {
        cidrs
            .iter()
            .find(|cidr| &cidr.name == parent_name)
            .ok_or_else(|| anyhow!("No parent CIDR with that name exists."))?
    } else {
        choose_cidr(cidrs, "Parent CIDR")?
    };
    let name = if let Some(ref name) = request.name {
        name.clone()
    } else {
        input("Name", Prefill::None)?
    };
    let cidr = if let Some(cidr) = request.cidr {
        cidr
    } else {
        input("CIDR", Prefill::None)?
    };
    let cidr_request = CidrContents {
        name: name.to_string(),
        cidr,
        parent: Some(parent_cidr.id),
    };
    Ok(
        if request.yes || confirm(&format!("Create CIDR \"{}\"?", cidr_request.name))? {
            Some(cidr_request)
        } else {
            None
        },
    )
}
pub fn add_cidr ( cidrs : & [ Cidr ] , request : & AddCidrOpts ) -> Result < Option < CidrContents > , Error > { let parent_cidr = if let Some ( ref parent_name ) = request . parent { cidrs . iter ( ) . find ( | cidr | & cidr . name == parent_name ) . ok_or_else ( | | anyhow ! ( " " ) ) ? } else { choose_cidr ( cidrs , " " ) ? } ; let name = if let Some ( ref name ) = request . name { name . clone ( ) } else { input ( " " , Prefill :: None ) ? } ; let cidr = if let Some ( cidr ) = request . cidr { cidr } else { input ( " " , Prefill :: None ) ? } ; let cidr_request = CidrContents { name : name . to_string ( ) , cidr , parent : Some ( parent_cidr . id ) , } ; Ok ( if request . yes || confirm ( & format ! ( " \" \" " cidr_request name ) ) ? { Some ( cidr_request ) } else { None } , ) }
Bring up a prompt to create a new CIDR.
Bring up a prompt to create a new CIDR .
cidrs
&[Cidr]
request
&AddCidrOpts