intelli_shell/process/
tldr_clear.rs1use tokio_util::sync::CancellationToken;
2
3use super::{Process, ProcessOutput};
4use crate::{
5 cli::TldrClearProcess, config::Config, errors::AppError, format_error, format_msg, service::IntelliShellService,
6};
7
8impl Process for TldrClearProcess {
9 async fn execute(
10 self,
11 config: Config,
12 service: IntelliShellService,
13 _cancellation_token: CancellationToken,
14 ) -> color_eyre::Result<ProcessOutput> {
15 match service.clear_tldr_commands(self.category).await {
16 Ok(0) => Ok(ProcessOutput::success().stderr(format_msg!(config.theme, "No commands were found"))),
17 Ok(deleted) => {
18 Ok(ProcessOutput::success().stderr(format_msg!(config.theme, "Removed {deleted} tldr commands")))
19 }
20 Err(AppError::UserFacing(err)) => Ok(ProcessOutput::fail().stderr(format_error!(config.theme, "{err}"))),
21 Err(AppError::Unexpected(report)) => Err(report),
22 }
23 }
24}