Skip to content

Commit 16fc5ef

Browse files
authored
Merge pull request #7 from radu-matei/feat/wrap-pkg
2 parents badd527 + 6ccf641 commit 16fc5ef

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
lines changed

Cargo.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ wit-bindgen-rust = { git = "https://github.com/fibonacci1729/wit-bindgen", branc
2727
wit-bindgen-core = { git = "https://github.com/fibonacci1729/wit-bindgen", branch = "deps" }
2828
wasm-pkg-common = "0.5.1"
2929
wasm-pkg-client = "0.5.1"
30+
wkg = "0.5.1"
3031

3132
[target.'cfg(target_os = "linux")'.dependencies]
3233
# This needs to be an explicit dependency to enable

src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod add;
22
pub mod bindings;
3+
pub mod publish;

src/commands/publish.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use anyhow::Result;
2+
use clap::Args;
3+
use std::path::PathBuf;
4+
use wasm_pkg_client::{Client, Config, PublishOpts};
5+
use wasm_pkg_common::{package::PackageSpec, registry::Registry};
6+
7+
#[derive(Args, Debug)]
8+
pub struct PublishCommand {
9+
/// The registry domain to use. Overrides configuration file(s).
10+
#[arg(long = "registry", value_name = "REGISTRY", env = "WKG_REGISTRY")]
11+
registry: Option<Registry>,
12+
13+
/// The file to publish
14+
file: PathBuf,
15+
16+
/// If not provided, the package name and version will be inferred from the Wasm file.
17+
/// Expected format: `<namespace>:<name>@<version>`
18+
#[arg(long, env = "WKG_PACKAGE")]
19+
package: Option<PackageSpec>,
20+
}
21+
22+
impl PublishCommand {
23+
pub async fn run(self) -> Result<()> {
24+
let client = {
25+
let config = Config::global_defaults()?;
26+
Client::new(config)
27+
};
28+
29+
let package = if let Some(package) = self.package {
30+
Some((
31+
package.package,
32+
package.version.ok_or_else(|| {
33+
anyhow::anyhow!("version is required when manually overriding the package ID")
34+
})?,
35+
))
36+
} else {
37+
None
38+
};
39+
let (package, version) = client
40+
.publish_release_file(
41+
&self.file,
42+
PublishOpts {
43+
package,
44+
registry: self.registry,
45+
},
46+
)
47+
.await?;
48+
println!("Published {}@{}", package, version);
49+
Ok(())
50+
}
51+
}

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clap::{Parser, Subcommand};
33

44
mod commands;
55
mod common;
6-
use commands::{add::AddCommand, bindings::GenerateBindingsCommand};
6+
use commands::{add::AddCommand, bindings::GenerateBindingsCommand, publish::PublishCommand};
77

88
/// Main CLI structure for command-line argument parsing.
99
#[derive(Parser)]
@@ -20,6 +20,9 @@ enum Commands {
2020
Add(AddCommand),
2121
/// Generates dependency bindings for selected component
2222
GenerateBindings(GenerateBindingsCommand),
23+
24+
/// Publish dependency to a compatible registry
25+
Publish(PublishCommand),
2326
}
2427

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

3438
Ok(())

0 commit comments

Comments
 (0)