use std::path::PathBuf;
use super::common::sanitize;
use crate::command::{Executable, build::lockfile::BuildLockfile};
#[derive(Debug, clap::Args)]
pub struct List {
#[clap(value_name = "DATAFLOW")]
dataflow: PathBuf,
}
impl Executable for List {
fn execute(self) -> eyre::Result<()> {
let lockfile_path = BuildLockfile::path_for_dataflow(&self.dataflow, None);
if !lockfile_path.exists() {
eyre::bail!(
"no lockfile at `{}` — run `dora build --write-lockfile {}` first",
lockfile_path.display(),
self.dataflow.display()
);
}
let lockfile = BuildLockfile::read_from(&lockfile_path)?;
let mut found = false;
for (node_id, source) in &lockfile.git_sources {
let Some(hub) = &source.hub else {
continue;
};
found = true;
let short: String = source.commit_hash.chars().take(12).collect();
println!(
"{node_id}: {} {} ({})",
sanitize(&hub.name),
sanitize(&hub.version),
sanitize(&short)
);
}
for (node_id, pin) in &lockfile.binary_sources {
found = true;
println!(
"{node_id}: {} {} (binary {})",
sanitize(&pin.hub.name),
sanitize(&pin.hub.version),
sanitize(&pin.platform)
);
}
if !found {
println!("No hub packages pinned in {}.", lockfile_path.display());
}
Ok(())
}
}