Expose more registry APIs (#2215)

This commit is contained in:
Jonathan Turner 2020-07-19 06:01:05 +12:00 committed by GitHub
parent 3432078e77
commit ebc2d40875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,30 +40,30 @@ impl CommandRegistry {
}
impl CommandRegistry {
pub(crate) fn get_command(&self, name: &str) -> Option<Command> {
pub fn get_command(&self, name: &str) -> Option<Command> {
let registry = self.registry.lock();
registry.get(name).cloned()
}
pub(crate) fn expect_command(&self, name: &str) -> Result<Command, ShellError> {
pub fn expect_command(&self, name: &str) -> Result<Command, ShellError> {
self.get_command(name).ok_or_else(|| {
ShellError::untagged_runtime_error(format!("Could not load command: {}", name))
})
}
pub(crate) fn has(&self, name: &str) -> bool {
pub fn has(&self, name: &str) -> bool {
let registry = self.registry.lock();
registry.contains_key(name)
}
pub(crate) fn insert(&mut self, name: impl Into<String>, command: Command) {
pub fn insert(&mut self, name: impl Into<String>, command: Command) {
let mut registry = self.registry.lock();
registry.insert(name.into(), command);
}
pub(crate) fn names(&self) -> Vec<String> {
pub fn names(&self) -> Vec<String> {
let registry = self.registry.lock();
registry.keys().cloned().collect()
}