use std::path::PathBuf;
use clap::Args;
use wash_lib::build::load_lock_file;
use wash_lib::cli::{CommandOutput, CommonPackageArgs};
use wash_lib::parser::{load_config, CommonConfig, ProjectConfig, RegistryConfig};
use wasm_pkg_core::wit::OutputType;
#[derive(Debug, Args, Clone)]
pub struct DepsArgs {
#[clap(short = 'd', long = "wit-dir", default_value = "wit")]
pub dir: PathBuf,
#[clap(short = 't', long = "type")]
pub output_type: Option<OutputType>,
#[clap(flatten)]
pub common: CommonPackageArgs,
#[clap(short = 'p', long = "config-path")]
config_path: Option<PathBuf>,
}
pub async fn invoke(
DepsArgs {
dir,
common,
config_path,
..
}: DepsArgs,
) -> anyhow::Result<CommandOutput> {
let project_config = match load_config(config_path.clone(), Some(true)).await {
Ok(v) => Some(v),
Err(e) => {
eprintln!("failed to load project configuration: {e}");
None
}
};
let wkg_config = match project_config {
Some(ProjectConfig {
ref package_config, ..
}) => package_config.clone(),
None => wasm_pkg_core::config::Config::load().await?,
};
let project_cfg = load_config(config_path, Some(true)).await?;
let mut lock_file = load_lock_file(&project_cfg.wasmcloud_toml_dir).await?;
let mut wkg = wash_lib::deps::WkgFetcher::from_common(&common, wkg_config).await?;
if let Some(ProjectConfig {
common:
CommonConfig {
registry:
RegistryConfig {
pull: Some(pull_cfg),
..
},
..
},
wasmcloud_toml_dir,
..
}) = project_config
{
wkg.resolve_extended_pull_configs(&pull_cfg, &wasmcloud_toml_dir)
.await?;
}
wkg.monkey_patch_fetch_logging(dir, &mut lock_file).await?;
lock_file.write().await?;
Ok("Dependencies fetched".into())
}