use clap::Args;
use eyre::Result;
use std::path::{Path, PathBuf};
use tracing::instrument;
use op_config::Config;
use op_stages::Stages;
#[derive(Debug, Args)]
pub struct UpCommand {
#[arg(long, short)]
pub config: Option<PathBuf>,
#[arg(long, short)]
pub devnet: bool,
#[arg(long, short)]
pub force: bool,
}
impl UpCommand {
pub fn new(config: Option<PathBuf>, devnet: bool) -> Self {
Self {
config,
devnet,
force: false,
}
}
async fn execute(&self) -> Result<()> {
tracing::info!("bootstrapping op stack");
crate::deps::DependencyManager::sync().await?;
if self.devnet {
tracing::info!("Building default devnet stack");
let config = Config::default().force_overwrites(self.force);
return Stages::from(config).execute().await;
}
let config_dir = self.config.as_ref().and_then(|p| p.parent());
let config_dir = config_dir.unwrap_or_else(|| Path::new("."));
tracing::info!("Using config directory: {:?}", config_dir);
let config = Config::load_with_root(config_dir).force_overwrites(self.force);
tracing::info!("Built config, executing stages");
Stages::from(config).execute().await
}
#[instrument(name = "up", target = "run", skip(self))]
pub fn run(&self) -> Result<()> {
crate::runner::run_until_ctrl_c(async { self.execute().await })
}
}