use crate::commands::invoke::InvokeCommand;
use crate::config::build_config;
use crate::error::Error;
use crate::function::Function;
use crate::runner::Runner;
use crate::writer::Writer;
use std::path::PathBuf;
pub(crate) struct InvokeRunner<'a> {
pub(crate) command: InvokeCommand,
pub(crate) writer: &'a Writer,
}
impl Runner for InvokeRunner<'_> {
async fn run(&mut self) -> Result<(), Error> {
let project = self.project().await?;
let all_functions = project.parse(
PathBuf::from(build_config()?.kinetics_path),
&[self.command.name.clone().into()],
)?;
let function = Function::find_by_name(&all_functions, &self.command.name)?;
let migrations_path = if self
.command
.with_migrations
.clone()
.unwrap_or_default()
.is_empty()
{
None
} else {
self.command.with_migrations.clone()
};
if !self.command.remote {
self.local(&function, migrations_path.as_deref()).await?
} else {
self.remote(&function).await?
}
Ok(())
}
}