mirror of
https://github.com/clap-rs/clap
synced 2025-01-18 23:53:54 +00:00
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:
parent
1321630ef5
commit
9b23e7ee40
1 changed files with 13 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue