pub struct OptionRegistry { /* private fields */ }Expand description
The project-wide registry of option definitions (the “common structure”).
It records one OptionDef per option name and rejects any attempt to
(re)define that name with a different shape. It does not store value
resolvers — those are per-command and attach to nodes directly.
Implementations§
Source§impl OptionRegistry
impl OptionRegistry
pub fn new() -> Self
Sourcepub fn define(&mut self, def: &OptionDef) -> Result<(), OptionConflict>
pub fn define(&mut self, def: &OptionDef) -> Result<(), OptionConflict>
Record def for its name, or verify it matches the existing record.
- first time a name is seen → recorded.
- seen again with an equal definition → accepted (shared use).
- seen again with a different definition →
OptionConflict.
Sourcepub fn attach(
&mut self,
opt: &dyn CommandOption,
) -> Result<(OptionDef, Option<ValueProvider>), OptionConflict>
pub fn attach( &mut self, opt: &dyn CommandOption, ) -> Result<(OptionDef, Option<ValueProvider>), OptionConflict>
Validate a CommandOption attachment and yield its per-command value
resolver. The definition is checked for consistency; the resolver (which
may vary per command) is returned for the caller to attach to that
command’s node.
Sourcepub fn get(&self, name: &str) -> Option<&OptionDef>
pub fn get(&self, name: &str) -> Option<&OptionDef>
The canonical definition recorded for an option name, if any.
pub fn is_empty(&self) -> bool
Sourcepub fn audit(&self, observed: &[(String, OptionDef)]) -> Vec<ParseMismatch>
pub fn audit(&self, observed: &[(String, OptionDef)]) -> Vec<ParseMismatch>
Runtime enforcement of “one parse-definition per option name” against the actual parser.
observed is every (command_path, OptionDef) extracted from the real
command/argument tree (e.g. the clap Command). For each option name the
audit collects the distinct parse_sigs seen —
plus the registered canonical definition, if any — and reports a
ParseMismatch for every name that has more than one. This catches the
case the registry’s define alone cannot: two commands declaring the
same flag with different arities, even though neither went through the
shared definition.