diff --git a/src/convert/flags.rs b/src/convert/flags.rs index 1c048f2..21540ed 100644 --- a/src/convert/flags.rs +++ b/src/convert/flags.rs @@ -37,23 +37,25 @@ impl FlagConverter { return Ok(()); } - fn write_list_flag(&self, pfx: &str, name: &str, v: &Val, w: &mut Write) -> Result<()> { - if let &Val::List(ref def) = v { - // first of all we need to make sure that each &Val is only a primitive type. - for v in def.iter() { - let vref = v.as_ref(); - if vref.is_list() || vref.is_tuple() || vref.is_macro() { - eprintln!( - "Skipping non primitive val in list for flag {}{}", - pfx, name - ); - } else { - try!(self.write_flag_name(pfx, name, w)); - try!(self.write(pfx, vref, w)); - } + fn write_list_flag( + &self, + pfx: &str, + name: &str, + def: &Vec>, + w: &mut Write, + ) -> Result<()> { + // first of all we need to make sure that each &Val is only a primitive type. + for v in def.iter() { + let vref = v.as_ref(); + if vref.is_list() || vref.is_tuple() || vref.is_macro() { + eprintln!( + "Skipping non primitive val in list for flag {}{}", + pfx, name + ); + } else { + try!(self.write_flag_name(pfx, name, w)); + try!(self.write(pfx, vref, w)); } - } else { - panic!("Impossible call happened. Somebody messed up.") } return Ok(()); } @@ -82,14 +84,18 @@ impl FlagConverter { try!(self.write_flag_name(pfx, &name.val, w)); continue; } - if val.is_tuple() { - let new_pfx = format!("{}{}.", pfx, name); - try!(self.write(&new_pfx, val, w)); - } else if val.is_list() { - try!(self.write_list_flag(pfx, &name.val, &val, w)); - } else { - try!(self.write_flag_name(pfx, &name.val, w)); - try!(self.write(pfx, &val, w)); + match val.as_ref() { + &Val::Tuple(_) => { + let new_pfx = format!("{}{}.", pfx, name); + try!(self.write(&new_pfx, val, w)); + } + &Val::List(ref def) => { + try!(self.write_list_flag(pfx, &name.val, def, w)); + } + _ => { + try!(self.write_flag_name(pfx, &name.val, w)); + try!(self.write(pfx, &val, w)); + } } }, &Val::Macro(ref _def) => {