use std::path::PathBuf;
use anyhow::{Context, Result};
use clap::Parser;
use hm_dsl_engine::{detect, engine_for};
#[derive(Debug, Clone, Parser)]
pub struct PipelinesArgs {
#[arg(short, long)]
pub dir: Option<PathBuf>,
}
const EMPTY_ENVELOPE: &str = r#"{"schema_version":"1","pipelines":[]}"#;
pub async fn run(args: PipelinesArgs) -> Result<()> {
let repo_root = match args.dir {
Some(d) => d,
None => std::env::current_dir().context("cannot determine current directory")?,
};
if !detect::has_pipeline_files(&repo_root) {
print!("{EMPTY_ENVELOPE}");
return Ok(());
}
let lang =
detect::detect_language_python_first(&repo_root).context("detecting pipeline language")?;
let engine = engine_for(lang).context("initializing DSL engine")?;
let json = engine
.registry_json(&repo_root)
.await
.context("dumping pipeline registry")?;
print!("{json}");
Ok(())
}