Skip to content

Commit 804922e

Browse files
committed
just enough machinery to run in a cli
1 parent 1e7d0fa commit 804922e

File tree

5 files changed

+309
-11
lines changed

5 files changed

+309
-11
lines changed

Cargo.lock

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

cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ name = "component-init"
88
path = "src/main.rs"
99

1010
[dependencies]
11+
anyhow.workspace = true
12+
clap = { version = "4", features = ["derive"] }
1113
component-init-wasmtime.workspace = true
14+
tokio = { version = "1", features = ["full"] }

cli/src/main.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1-
fn main() {
2-
println!("Hello, world!");
1+
use anyhow::{Context, Result};
2+
use clap::Parser;
3+
use std::path::PathBuf;
4+
5+
/// Initialize a component. Saves the internal state of the component
6+
/// after its `component-init` export function has been called.
7+
#[derive(Parser, Debug)]
8+
#[command(version, about, long_about = None)]
9+
struct Args {
10+
/// Input component.
11+
#[arg(required = true)]
12+
input: PathBuf,
13+
14+
/// Output component. If not provided, output will overwrite input.
15+
#[arg(short, long)]
16+
output: Option<PathBuf>,
17+
}
18+
19+
#[tokio::main]
20+
async fn main() -> Result<()> {
21+
let args = Args::parse();
22+
23+
let infile = &args.input;
24+
let input =
25+
std::fs::read(infile).with_context(|| format!("reading input from {:?}", infile))?;
26+
let output = component_init_wasmtime::initialize(&input).await?;
27+
28+
let outfile = args.output.as_ref().unwrap_or(infile);
29+
std::fs::write(outfile, output).with_context(|| format!("writing output to {:?}", outfile))?;
30+
Ok(())
331
}

wasmtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ version.workspace = true
44
edition.workspace = true
55

66
[dependencies]
7+
anyhow.workspace = true
8+
async-trait.workspace = true
79
component-init.workspace = true
810
wasmtime.workspace = true
911
wasmtime-wasi.workspace = true

0 commit comments

Comments
 (0)