add prettier CommandTree formatting for help command and usage hint

This commit is contained in:
user622628252416 committed 2024-08-21 17:59:54 +02:00
1 parent 59a4fe525d
commit 5041b441eb
9 files changed
+185 -81

No files matched your search

+14 -4
View File
@@ -49,10 +49,7 @@ impl<'a> CommandDispatcher<'a> {
}
}
Err(format!(
"Invalid Syntax. Usage:{}",
tree.paths_formatted(key)
))
Err(format!("Invalid Syntax. Usage: {}", tree))
}
fn try_is_fitting_path(
@@ -99,4 +96,17 @@ impl<'a> CommandDispatcher<'a> {
Ok(false)
}
/// Register a command with the dispatcher.
pub(crate) fn register(&mut self, tree: CommandTree<'a>) {
let mut names = tree.names.iter();
let primary_name = names.next().expect("at least one name must be provided");
for &name in names {
self.commands.insert(name, tree.clone());
}
self.commands.insert(primary_name, tree);
}
}