shared(prompts): simplify cidr selection code
parent
f27a2426c8
commit
76500b3778
|
@ -76,16 +76,15 @@ pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result<Option<CidrCont
|
|||
}
|
||||
|
||||
pub fn choose_cidr<'a>(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>(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue