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