Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ wit-bindgen-rust = { git = "https://github.com/fibonacci1729/wit-bindgen", branc
wit-bindgen-core = { git = "https://github.com/fibonacci1729/wit-bindgen", branch = "deps" }
wasm-pkg-common = "0.5.1"
wasm-pkg-client = "0.5.1"
wkg = "0.5.1"

[target.'cfg(target_os = "linux")'.dependencies]
# This needs to be an explicit dependency to enable
Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod add;
pub mod bindings;
pub mod publish;
51 changes: 51 additions & 0 deletions src/commands/publish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use anyhow::Result;
use clap::Args;
use std::path::PathBuf;
use wasm_pkg_client::{Client, Config, PublishOpts};
use wasm_pkg_common::{package::PackageSpec, registry::Registry};

#[derive(Args, Debug)]
pub struct PublishCommand {
/// The registry domain to use. Overrides configuration file(s).
#[arg(long = "registry", value_name = "REGISTRY", env = "WKG_REGISTRY")]
registry: Option<Registry>,

/// The file to publish
file: PathBuf,

/// If not provided, the package name and version will be inferred from the Wasm file.
/// Expected format: `<namespace>:<name>@<version>`
#[arg(long, env = "WKG_PACKAGE")]
package: Option<PackageSpec>,
}

impl PublishCommand {
pub async fn run(self) -> Result<()> {
let client = {
let config = Config::global_defaults()?;
Client::new(config)
};

let package = if let Some(package) = self.package {
Some((
package.package,
package.version.ok_or_else(|| {
anyhow::anyhow!("version is required when manually overriding the package ID")
})?,
))
} else {
None
};
let (package, version) = client
.publish_release_file(
&self.file,
PublishOpts {
package,
registry: self.registry,
},
)
.await?;
println!("Published {}@{}", package, version);
Ok(())
}
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::{Parser, Subcommand};

mod commands;
mod common;
use commands::{add::AddCommand, bindings::GenerateBindingsCommand};
use commands::{add::AddCommand, bindings::GenerateBindingsCommand, publish::PublishCommand};

/// Main CLI structure for command-line argument parsing.
#[derive(Parser)]
Expand All @@ -20,6 +20,9 @@ enum Commands {
Add(AddCommand),
/// Generates dependency bindings for selected component
GenerateBindings(GenerateBindingsCommand),

/// Publish dependency to a compatible registry
Publish(PublishCommand),
}

#[tokio::main]
Expand All @@ -29,6 +32,7 @@ async fn main() -> Result<()> {
match app.command {
Commands::Add(cmd) => cmd.run().await?,
Commands::GenerateBindings(cmd) => cmd.run().await?,
Commands::Publish(cmd) => cmd.run().await?,
}

Ok(())
Expand Down
Loading