use std::path::{Path, PathBuf};
use anyhow::{bail, Result};
use clap::Args;
use super::init::compose::ComposeRunner;
#[derive(Args)]
pub struct RestartArgs {
#[arg(long, default_value = "~/.aegis")]
pub dir: String,
#[arg(long)]
pub profile: Option<String>,
}
pub async fn run(args: RestartArgs) -> Result<()> {
let dir = expand_tilde(Path::new(&args.dir));
if !dir.join("docker-compose.yml").exists() {
bail!(
"No docker-compose.yml found in {}.\nHave you run `aegis init`?",
dir.display()
);
}
let runner = ComposeRunner::new(dir);
runner.restart(args.profile.as_deref()).await
}
fn expand_tilde(path: &Path) -> PathBuf {
if let Ok(stripped) = path.strip_prefix("~") {
if let Some(home) = dirs_next::home_dir() {
return home.join(stripped);
}
}
path.to_path_buf()
}