pub struct Node { /* private fields */ }Expand description
Carries two metadata fields used by stratified (multi-tap) completion:
category— free-form display tag. Apps can group root commands by category in expanded help / future renderers (e.g.workloads,documentation,tools).level— visibility tier. The Nth tab tap reveals every root-level node withlevel <= N. DefaultDEFAULT_LEVEL(= 1) means “always shown from the first tap.” Use a higher level (2, 3, …) for less-discoverable commands so the first tap stays focused on a small set the user wants by default.
Existing callers that didn’t set these fields get the pre-existing behavior automatically (everything visible at tap 1, no category metadata).
A node in the command tree. Carries everything a command-tree node can have: subcommand children, flags, providers, discovery metadata, help text, and a free-form attachment slot.
“Leaf” and “Group” are no longer separate variants. A node with
no children is leaf-shaped; a node with children is group-shaped;
a node with both is hybrid (e.g., report --workload x base,
where report accepts --workload and has a base subcommand).
Walkers branch on children.is_empty() only when the distinction
actually matters.
All builder methods (with_*) return self so they chain.
Methods that operate on children (e.g. with_child) work on
any node — calling them just adds the child, regardless of
whether the node was previously leaf-shaped or not.
Implementations§
Source§impl Node
impl Node
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty node — no flags, no children, no metadata. Build up
from here using the with_* builders.
Sourcepub fn leaf(flags: &[&str]) -> Self
pub fn leaf(flags: &[&str]) -> Self
Convenience: a leaf-shaped node carrying the supplied value-taking flags (none of them booleans).
Sourcepub fn leaf_with_flags(value_flags: &[&str], boolean_flags: &[&str]) -> Self
pub fn leaf_with_flags(value_flags: &[&str], boolean_flags: &[&str]) -> Self
Convenience: a leaf-shaped node with separate value-taking and boolean flag lists.
Sourcepub fn group(children: Vec<(&str, Node)>) -> Self
pub fn group(children: Vec<(&str, Node)>) -> Self
Convenience: a group-shaped node from a list of (name, child)
pairs. Add flags to the group separately via Node::with_flags
/ Node::with_boolean_flags.
Sourcepub fn empty_group() -> Self
pub fn empty_group() -> Self
Empty group — no children, no flags. Add via Node::with_child.
Sourcepub fn is_leaf(&self) -> bool
pub fn is_leaf(&self) -> bool
Leaf-shaped if it has no children. A node with both flags AND children is not leaf-shaped — it’s hybrid.
Sourcepub fn with_child(self, name: &str, child: Node) -> Self
pub fn with_child(self, name: &str, child: Node) -> Self
Add a child to this node. Works on any node; if the node was previously leaf-shaped, this turns it into a hybrid (flags + children).
Sourcepub fn children(&self) -> &BTreeMap<String, Node>
pub fn children(&self) -> &BTreeMap<String, Node>
Direct access to children (empty for leaf-shaped nodes).
Sourcepub fn children_mut(&mut self) -> &mut BTreeMap<String, Node>
pub fn children_mut(&mut self) -> &mut BTreeMap<String, Node>
Mutable access to children — used by internal walkers.
Sourcepub fn child_names(&self) -> Vec<&str>
pub fn child_names(&self) -> Vec<&str>
Names of this node’s children, in BTreeMap order.
Sourcepub fn with_flags(self, flags: &[&str]) -> Self
pub fn with_flags(self, flags: &[&str]) -> Self
Add value-taking flags to this node. Idempotent — duplicates are skipped.
Sourcepub fn with_boolean_flags(self, flags: &[&str]) -> Self
pub fn with_boolean_flags(self, flags: &[&str]) -> Self
Add boolean flags (no value expected) to this node. Idempotent.
Sourcepub fn with_short_alias(self, short: &str, long: &str) -> Self
pub fn with_short_alias(self, short: &str, long: &str) -> Self
Register a short alias (-c) for a long flag (--config).
The alias participates in value-position detection and value
completion exactly like the long form.
Sourcepub fn flags(&self) -> &[String]
pub fn flags(&self) -> &[String]
All flag names this node accepts (value-taking + boolean), in declared order.
Sourcepub fn options(&self) -> Vec<&str>
pub fn options(&self) -> Vec<&str>
Convenience accessor — same as Node::flags but as a Vec<&str>.
Kept for callers that prefer the &str view.
Sourcepub fn with_value_provider(self, flag: &str, provider: ValueProvider) -> Self
pub fn with_value_provider(self, flag: &str, provider: ValueProvider) -> Self
Attach a value provider to one of this node’s flags.
Sourcepub fn with_flag_conflict(self, flag: &str, conflicts: &str) -> Self
pub fn with_flag_conflict(self, flag: &str, conflicts: &str) -> Self
Declare that flag cannot be combined with conflicts —
once conflicts is on the line, flag is withheld from
completion. One direction only; callers wanting symmetric
exclusion (the normal case — see
cli::build_completion_tree) register both directions.
Sourcepub fn with_value_provider_aliases(
self,
aliases: &[&str],
provider: ValueProvider,
) -> Self
pub fn with_value_provider_aliases( self, aliases: &[&str], provider: ValueProvider, ) -> Self
Attach the same value provider to every name in aliases —
e.g. --tofile and --to-file.
Sourcepub fn value_providers(&self) -> &BTreeMap<String, ValueProvider>
pub fn value_providers(&self) -> &BTreeMap<String, ValueProvider>
Direct access to the value-provider map (used by walkers).
Sourcepub fn with_positional_provider(self, provider: ValueProvider) -> Self
pub fn with_positional_provider(self, provider: ValueProvider) -> Self
Attach a provider for this command’s first positional argument.
Sourcepub fn positional_provider(&self) -> Option<&ValueProvider>
pub fn positional_provider(&self) -> Option<&ValueProvider>
The first-positional provider, if any.
Sourcepub fn with_positional_slots(self, slots: usize) -> Self
pub fn with_positional_slots(self, slots: usize) -> Self
Declare how many positional slots the provider serves. The provider receives the completed words and decides per slot.
Sourcepub fn with_dynamic_options(self, provider: DynamicOptionsProvider) -> Self
pub fn with_dynamic_options(self, provider: DynamicOptionsProvider) -> Self
Attach a dynamic options provider.
The provider is called during completion to discover
additional key= options from context (e.g., workload-file
parameters).
Sourcepub fn dynamic_options(&self) -> Option<DynamicOptionsProvider>
pub fn dynamic_options(&self) -> Option<DynamicOptionsProvider>
The attached dynamic options provider, if any.
Sourcepub fn with_category(self, cat: &str) -> Self
pub fn with_category(self, cat: &str) -> Self
Tag this node with a display category.
Sourcepub fn with_stability(self, stability: Stability) -> Self
pub fn with_stability(self, stability: Stability) -> Self
Declare this command’s maturity tier (see Stability). Controls
whether it’s offered during completion at the active threshold.
Sourcepub fn stability(&self) -> Stability
pub fn stability(&self) -> Stability
This node’s maturity tier (default Stability::Stable).
Sourcepub fn with_level(self, lvl: u32) -> Self
pub fn with_level(self, lvl: u32) -> Self
Set the tap-tier visibility for this node.
Sourcepub fn level(&self) -> u32
pub fn level(&self) -> u32
Effective tap-tier level — explicit value if set, otherwise
DEFAULT_LEVEL.
Sourcepub fn level_explicit(&self) -> Option<u32>
pub fn level_explicit(&self) -> Option<u32>
Explicit tap-tier level — None when with_level was never
called. Used by strict-metadata validation.
Sourcepub fn with_flag_help(self, flag: &str, help: &str) -> Self
pub fn with_flag_help(self, flag: &str, help: &str) -> Self
Attach help text for one of this node’s flags.
Sourcepub fn with_flag_long_help(self, flag: &str, help: &str) -> Self
pub fn with_flag_long_help(self, flag: &str, help: &str) -> Self
Builder: register extended help for a flag — surfaced on a
rapid triple-tap at the value position. Mirrors clap’s
Arg::long_help shape.
Sourcepub fn flag_long_help_for(&self, flag: &str) -> Option<&str>
pub fn flag_long_help_for(&self, flag: &str) -> Option<&str>
Lookup extended help for a flag.
Sourcepub fn flag_help_for(&self, flag: &str) -> Option<&str>
pub fn flag_help_for(&self, flag: &str) -> Option<&str>
Get help text for one of this node’s flags, if any.
Sourcepub fn with_subtree_provider(self, provider: SubtreeProvider) -> Self
pub fn with_subtree_provider(self, provider: SubtreeProvider) -> Self
Attach a context-aware completion override for this subtree.
Sourcepub fn subtree_provider(&self) -> Option<&SubtreeProvider>
pub fn subtree_provider(&self) -> Option<&SubtreeProvider>
The subtree provider, if any.
Sourcepub fn with_extras(self, extras: Extras) -> Self
pub fn with_extras(self, extras: Extras) -> Self
Attach a free-form payload (handler, parser state, etc.).