imp(parser.rs): Expose Parser's flags, opts and positionals argument as iterators

Writing the help requires read only access to Parser's flags, opts
and positionals. This commit provides 3 functions returning iterators
over those collections (`iter_*`) allowing to have function outside
the parser to generate the help.
This commit is contained in:
Hernan Grecco 2016-03-31 21:22:59 -03:00
parent 1321630ef5
commit 9b23e7ee40

View file

@ -6,7 +6,7 @@ use std::fmt::Display;
#[cfg(feature = "debug")]
use std::os::unix::ffi::OsStrExt;
use vec_map::VecMap;
use vec_map::{self, VecMap};
use app::App;
use args::{Arg, FlagBuilder, OptBuilder, ArgGroup, PosBuilder};
@ -1570,6 +1570,18 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
}
Ok(())
}
pub fn iter_flags(&self) -> Iter<FlagBuilder> {
self.flags.iter()
}
pub fn iter_opts(&self) -> Iter<OptBuilder> {
self.opts.iter()
}
pub fn iter_positionals(&self) -> vec_map::Values<PosBuilder> {
self.positionals.values()
}
}
impl<'a, 'b> Clone for Parser<'a, 'b> where 'a: 'b {