use std::rc::Rc;
use std::collections::BTreeSet;
use std::fmt::{ Display, Formatter, Result };
use std::result::Result as StdResult;
pub struct OptBuilder<'n> {
pub name: &'n str,
pub short: Option<char>,
pub long: Option<&'n str>,
pub help: Option<&'n str>,
pub multiple: bool,
pub blacklist: Option<Vec<&'n str>>,
pub required: bool,
pub possible_vals: Option<BTreeSet<&'n str>>,
pub requires: Option<Vec<&'n str>>,
pub num_vals: Option<u8>,
pub min_vals: Option<u8>,
pub max_vals: Option<u8>,
pub val_names: Option<Vec<&'n str>>,
pub empty_vals: bool,
pub global: bool,
pub validator: Option<Rc<Fn(String) -> StdResult<(), String>>>,
pub overrides: Option<Vec<&'n str>>
}
impl<'n> Display for OptBuilder<'n> {
fn fmt(&self, f: &mut Formatter) -> Result {
if let Some(l) = self.long {
try!(write!(f, "--{}", l));
} else {
try!(write!(f, "-{}", self.short.unwrap()));
}
if let Some(ref vec) = self.val_names {
for n in vec.iter() {
try!(write!(f, " <{}>", n));
}
} else {
let num = self.num_vals.unwrap_or(1);
for _ in (0..num) {
try!(write!(f, " <{}>", self.name));
}
if self.multiple && num == 1 {
try!(write!(f, "..."));
}
}
Ok(())
}
}