diff --git a/shared/src/prompts.rs b/shared/src/prompts.rs index 3f4d4f7..630b5e9 100644 --- a/shared/src/prompts.rs +++ b/shared/src/prompts.rs @@ -76,16 +76,15 @@ pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result(cidrs: &'a [Cidr], text: &'static str) -> Result<&'a Cidr, Error> { - let cidr_names: Vec<_> = cidrs + let eligible_cidrs: Vec<_> = cidrs .iter() .filter(|cidr| cidr.name != "innernet-server") - .map(|cidr| format!("{} ({})", &cidr.name, &cidr.cidr)) .collect(); let cidr_index = Select::with_theme(&*THEME) .with_prompt(text) - .items(&cidr_names) + .items(&eligible_cidrs) .interact()?; - Ok(&cidrs[cidr_index]) + Ok(&eligible_cidrs[cidr_index]) } pub fn choose_association<'a>( diff --git a/shared/src/types.rs b/shared/src/types.rs index 2072dc3..d7f9d0f 100644 --- a/shared/src/types.rs +++ b/shared/src/types.rs @@ -199,6 +199,12 @@ pub struct Cidr { pub contents: CidrContents, } +impl Display for Cidr { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{} ({})", self.name, self.cidr) + } +} + impl Deref for Cidr { type Target = CidrContents;