intelli_shell/process/
replace.rs1use color_eyre::eyre::Result;
2use tracing::instrument;
3
4use super::{InteractiveProcess, Process, ProcessOutput};
5use crate::{
6 cli::VariableReplaceProcess,
7 component::{Component, variable::VariableReplacementComponent},
8 config::Config,
9 format_error,
10 model::DynamicCommand,
11 service::IntelliShellService,
12};
13
14impl Process for VariableReplaceProcess {
15 async fn execute(self, config: Config, service: IntelliShellService) -> Result<ProcessOutput> {
16 match service.replace_command_variables(self.command.into_inner(), self.values, self.use_env) {
17 Ok(command) => Ok(ProcessOutput::success().stdout(&command).fileout(command)),
18 Err(missing) => Ok(ProcessOutput::fail().stderr(format_error!(
19 config.theme,
20 "Missing variable values: {}",
21 missing.join(", ")
22 ))),
23 }
24 }
25}
26
27impl InteractiveProcess for VariableReplaceProcess {
28 #[instrument(skip_all)]
29 fn into_component(self, config: Config, service: IntelliShellService, inline: bool) -> Result<Box<dyn Component>> {
30 let command = DynamicCommand::parse(self.command.into_inner(), true);
31 Ok(Box::new(VariableReplacementComponent::new(
32 service,
33 config.theme,
34 inline,
35 false,
36 true,
37 command,
38 )))
39 }
40}