intelli_shell/process/
completion_delete.rs

1use color_eyre::Result;
2
3use super::{Process, ProcessOutput};
4use crate::{
5    cli::CompletionDeleteProcess, config::Config, errors::AppError, format_error, format_msg,
6    service::IntelliShellService,
7};
8
9impl Process for CompletionDeleteProcess {
10    async fn execute(self, config: Config, service: IntelliShellService) -> Result<ProcessOutput> {
11        let root_cmd = self.command.as_deref().unwrap_or_default();
12        let variable_name = &self.variable;
13        match service.delete_variable_completion_by_key(root_cmd, variable_name).await {
14            Ok(None) if root_cmd.trim().is_empty() => Ok(ProcessOutput::fail().stderr(format_error!(
15                config.theme,
16                "Completion for global {} variable not found",
17                config.theme.secondary.apply(variable_name),
18            ))),
19            Ok(None) => Ok(ProcessOutput::fail().stderr(format_error!(
20                config.theme,
21                "Completion for {} variable within {} commands not found",
22                config.theme.secondary.apply(variable_name),
23                config.theme.secondary.apply(&root_cmd),
24            ))),
25            Ok(Some(c)) if c.is_global() => Ok(ProcessOutput::success().stderr(format_msg!(
26                config.theme,
27                "Completion for global {} variable deleted",
28                config.theme.secondary.apply(&c.variable),
29            ))),
30            Ok(Some(c)) => Ok(ProcessOutput::success().stderr(format_msg!(
31                config.theme,
32                "Completion for {} variable within {} commands deleted",
33                config.theme.secondary.apply(&c.variable),
34                config.theme.secondary.apply(&c.root_cmd),
35            ))),
36            Err(AppError::UserFacing(err)) => Ok(ProcessOutput::fail().stderr(format_error!(config.theme, "{err}"))),
37            Err(AppError::Unexpected(report)) => Err(report),
38        }
39    }
40}