Skip to main content

bijux_cli/routing/
catalog.rs

1#![forbid(unsafe_code)]
2//! Canonical command catalog for normalization and route recognition.
3
4fn contains(values: &[&str], value: &str) -> bool {
5    values.contains(&value)
6}
7
8/// Canonical CLI root aliases supported by route normalization.
9#[must_use]
10pub fn cli_root_aliases() -> &'static [&'static str] {
11    super::model::CLI_ROOT_ALIASES
12}
13
14/// Canonical `cli config` subcommands supported by route normalization.
15#[must_use]
16pub fn cli_config_subcommands() -> &'static [&'static str] {
17    super::model::CLI_CONFIG_SUBCOMMANDS
18}
19
20/// Canonical `cli plugins` subcommands supported by route normalization.
21#[must_use]
22pub fn cli_plugins_subcommands() -> &'static [&'static str] {
23    super::model::CLI_PLUGINS_SUBCOMMANDS
24}
25
26/// Normalize path aliases into canonical command paths.
27#[must_use]
28pub fn normalize_command_path(path: &[String]) -> Vec<String> {
29    match path {
30        [a] if contains(super::model::CLI_ROOT_ALIASES, a) => vec!["cli".to_string(), a.clone()],
31        [a, b] if a == "config" && contains(super::model::CLI_CONFIG_SUBCOMMANDS, b) => {
32            vec!["cli".to_string(), "config".to_string(), b.clone()]
33        }
34        [a, b] if a == "plugins" && contains(super::model::CLI_PLUGINS_SUBCOMMANDS, b) => {
35            vec!["cli".to_string(), "plugins".to_string(), b.clone()]
36        }
37        _ => path.to_vec(),
38    }
39}
40
41/// Return true when normalized path is a known built-in command route.
42#[must_use]
43pub fn is_known_route(path: &[String]) -> bool {
44    super::model::is_known_route(path)
45}
46
47/// REPL reference commands rendered in command help.
48#[must_use]
49pub fn repl_reference_commands() -> &'static [&'static str] {
50    super::model::REPL_REFERENCE_COMMANDS
51}