pub struct Registry {
pub props: &'static [PropMeta],
}Expand description
Every setting a CLI has.
Fields§
§props: &'static [PropMeta]Implementations§
Source§impl Registry
impl Registry
pub const fn new(props: &'static [PropMeta]) -> Self
pub fn get(&self, id: PropId) -> &'static PropMeta
Sourcepub fn lookup(&self, key: &str) -> Option<Lookup>
pub fn lookup(&self, key: &str) -> Option<Lookup>
The id of a dotted key, following a rename to the setting that replaced it.
Linear, because a registry is small and a lookup happens once per key a layer supplies — not once per key that exists. A binary search over a sorted table would be a fine optimization and is not yet worth the invariant it demands of the generator.
Sourcepub fn lookup_exact(&self, key: &str) -> Option<PropId>
pub fn lookup_exact(&self, key: &str) -> Option<PropId>
The id of a dotted key, without following a rename.
Registry::lookup answers “which setting does this key mean”, which is what a reader
wants. This answers “which declaration is this key”, which is what a warning wants: the
deprecation message lives on the old name’s own declaration.
Sourcepub fn names_file_value(&self, key: &str) -> bool
pub fn names_file_value(&self, key: &str) -> bool
Whether a table at key is itself a setting value rather than a path to
more-specific settings.
Aliases participate in file lookup, but an alias that is also the prefix of a declared dotted key must not swallow that nested value. A leaf alias for a map or object still names the whole table.
Sourcepub fn deprecation_meta(&self, key: &str) -> Option<&'static PropMeta>
pub fn deprecation_meta(&self, key: &str) -> Option<&'static PropMeta>
The first deprecated declaration along the rename chain that starts at key.
The chain, not the declaration named: a renamed to b, and b the one carrying the notice
that says to use c. A user who wrote a is being told the same thing either way, and which
release the notice was attached in is not something they can see.
Bounded by the number of settings there are, so a registry whose renames form a cycle stops
rather than following them forever — the same guard Registry::lookup uses, and for the
same reason: this is an authoring mistake, and hanging is a worse way to report one than
nothing at all. The derive refuses such a declaration outright.
Sourcepub fn deprecation(&self, key: &str) -> Option<&'static str>
pub fn deprecation(&self, key: &str) -> Option<&'static str>
The first deprecation notice along the rename chain that starts at key.
Kept as the message-only counterpart to Registry::deprecation_meta for callers that do
not need lifecycle milestones.
Sourcepub fn ids(&self) -> impl Iterator<Item = PropId>
pub fn ids(&self) -> impl Iterator<Item = PropId>
The settings an environment variable sets, and the variable that set them.
Several names per setting are aliases in descending precedence, which the env layer honours by taking the first one that is present.
Sourcepub fn drift(&self, bound: &[(&str, &str)]) -> Vec<String>
pub fn drift(&self, bound: &[(&str, &str)]) -> Vec<String>
Every way the flags a spec declares and the flags a CLI binds disagree.
Empty means they agree. This is the check hk needed and did not have: it declares eighteen
sources.cli bindings and reads five, because the declaration lives in a spec and the
reading lives in a hand-written struct, and nothing has ever compared the two. A spec that
documents --jobs and a CLI that never puts it anywhere is a promise to a user that no test
could catch.
bound is what the CLI actually does: pairs of a flag and the setting it sets. A CLI whose
flags come from usage::Cli can generate that list; one that binds by hand writes it out,
which is still one list rather than two behaviours.
Both directions are reported, because they are different mistakes. A declared flag nothing
binds is documentation for something that does not happen. A bound flag the setting does not
declare happens without being documented — the user cannot discover it, and explain cannot
name it.
Sourcepub fn bindings(
&self,
kind: SourceKind,
) -> impl Iterator<Item = (PropId, &'static str)> + use<'_>
pub fn bindings( &self, kind: SourceKind, ) -> impl Iterator<Item = (PropId, &'static str)> + use<'_>
Every setting bound to kind, with its key in that source.
The generic mechanism a custom layer is written against: a git layer asks for "git"
and reads the keys it gets back, without usage knowing anything about git.