tideway_cli/commands/
dev.rs1use anyhow::{Context, Result};
4use std::path::PathBuf;
5use std::process::Command;
6
7use crate::cli::DevArgs;
8use crate::is_plan_mode;
9use crate::env::{ensure_env, ensure_project_dir, read_env_map};
10use crate::{print_info, print_success};
11
12pub fn run(args: DevArgs) -> Result<()> {
13 if is_plan_mode() {
14 print_info("Plan: would run tideway dev (cargo run) with env + migrations");
15 return Ok(());
16 }
17 let project_dir = PathBuf::from(&args.path);
18 ensure_project_dir(&project_dir)?;
19
20 if !args.no_env {
21 ensure_env(&project_dir, args.fix_env)?;
22 }
23
24 let mut command = Command::new("cargo");
25 command.arg("run").current_dir(&project_dir);
26
27 if !args.args.is_empty() {
28 command.args(&args.args);
29 }
30
31 if !args.no_env {
32 if let Some(env_map) = read_env_map(&project_dir.join(".env")) {
33 command.envs(env_map);
34 }
35 }
36
37 if !args.no_migrate {
38 command.env("DATABASE_AUTO_MIGRATE", "true");
39 }
40
41 print_info("Starting Tideway app...");
42 let status = command.status().context("Failed to run cargo")?;
43
44 if status.success() {
45 print_success("Process exited cleanly");
46 Ok(())
47 } else {
48 Err(anyhow::anyhow!("cargo exited with status {}", status))
49 }
50}