Skip to main content

clash_brush_core/shell/
builtin_registry.rs

1//! Builtin command management for shell instances.
2
3use std::collections::HashMap;
4
5use crate::{builtins, extensions};
6
7impl<SE: extensions::ShellExtensions> crate::Shell<SE> {
8    /// Register a builtin to the shell's environment.
9    ///
10    /// # Arguments
11    ///
12    /// * `name` - The in-shell name of the builtin.
13    /// * `registration` - The registration handle for the builtin.
14    pub fn register_builtin<S: Into<String>>(
15        &mut self,
16        name: S,
17        registration: builtins::Registration<SE>,
18    ) {
19        self.builtins.insert(name.into(), registration);
20    }
21
22    /// Tries to retrieve a mutable reference to an existing builtin registration.
23    /// Returns `None` if no such registration exists.
24    ///
25    /// # Arguments
26    ///
27    /// * `name` - The name of the builtin to lookup.
28    pub fn builtin_mut(&mut self, name: &str) -> Option<&mut builtins::Registration<SE>> {
29        self.builtins.get_mut(name)
30    }
31
32    /// Returns the registered builtins for the shell.
33    pub const fn builtins(&self) -> &HashMap<String, builtins::Registration<SE>> {
34        &self.builtins
35    }
36}