use std::time::Instant;
use crate::colors;
use crate::executor::NotebookExecutor;
use crate::output::print_output;
pub fn execute(
notebook_path: &str,
cell_filter: Option<&str>,
release: bool,
) -> anyhow::Result<()> {
let start = Instant::now();
let executor = NotebookExecutor::new(notebook_path, release)?;
executor.print_header("Running");
if executor.cells.is_empty() {
println!(
"\n{}No cells found in notebook.{}",
colors::YELLOW,
colors::RESET
);
println!("Cells are functions marked with #[venus::cell]");
return Ok(());
}
let compilation = executor.compile()?;
let execution = executor.execute(&compilation, cell_filter)?;
println!("\n{}Outputs:{}", colors::BOLD, colors::RESET);
println!("{}", "─".repeat(50));
for &cell_id in &execution.executed_cells {
if let Some(cell) = executor.cell_by_id(cell_id)
&& let Some(output) = execution.outputs.get(&cell_id)
{
print_output(&cell.name, &cell.return_type, output.bytes());
}
}
let total_time = start.elapsed();
println!("\n{}", "─".repeat(50));
println!(
"{}Completed{} {} cells in {:.2}s (execution: {:.2}s)",
colors::GREEN,
colors::RESET,
execution.executed_cells.len(),
total_time.as_secs_f64(),
execution.execution_time.as_secs_f64()
);
Ok(())
}