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