intelli_shell/process/
completion_list.rs1use color_eyre::Result;
2use itertools::Itertools;
3use tokio_util::sync::CancellationToken;
4
5use super::{Process, ProcessOutput};
6use crate::{
7 cli::CompletionListProcess,
8 component::{Component, completion_list::CompletionListComponent},
9 config::Config,
10 errors::AppError,
11 format_error,
12 process::InteractiveProcess,
13 service::IntelliShellService,
14};
15
16impl Process for CompletionListProcess {
17 async fn execute(
18 self,
19 config: Config,
20 service: IntelliShellService,
21 _cancellation_token: CancellationToken,
22 ) -> Result<ProcessOutput> {
23 match service.list_variable_completions(self.command.as_deref()).await {
24 Ok(completions) => {
25 Ok(ProcessOutput::success().stdout(completions.into_iter().map(|c| c.to_string()).join("\n")))
26 }
27 Err(AppError::UserFacing(err)) => Ok(ProcessOutput::fail().stderr(format_error!(config.theme, "{err}"))),
28 Err(AppError::Unexpected(report)) => Err(report),
29 }
30 }
31}
32
33impl InteractiveProcess for CompletionListProcess {
34 fn into_component(
35 self,
36 config: Config,
37 service: IntelliShellService,
38 inline: bool,
39 cancellation_token: CancellationToken,
40 ) -> Result<Box<dyn Component>> {
41 Ok(Box::new(CompletionListComponent::new(
42 service,
43 config,
44 inline,
45 self.command,
46 cancellation_token,
47 )))
48 }
49}