use std::path::PathBuf;
use clap::Args;
use wash_lib::{
cli::{CommandOutput, CommonPackageArgs},
deps::WkgFetcher,
};
use wasm_pkg_client::{PublishOpts, Registry};
#[derive(Args, Debug, Clone)]
pub struct PublishArgs {
file: PathBuf,
#[arg(long = "wit-registry", env = "WASH_WIT_REGISTRY")]
registry: Option<Registry>,
#[command(flatten)]
common: CommonPackageArgs,
}
pub async fn invoke(
PublishArgs {
file,
registry,
common,
}: PublishArgs,
) -> anyhow::Result<CommandOutput> {
let client = WkgFetcher::from_common(&common, wasm_pkg_core::config::Config::default())
.await?
.into_client();
let (package, version) = client
.client()?
.publish_release_file(
&file,
PublishOpts {
registry,
..Default::default()
},
)
.await?;
Ok(CommandOutput::new(
format!("Published {}@{}", package, version),
[
("package".to_string(), package.to_string().into()),
("version".to_string(), version.to_string().into()),
]
.into(),
))
}