bytecodealliance / bytecodealliance/wasmtime

[wasmtime CLI]: Expose component interfaces as CLI sub-commands

Open
#10,637 6 comments 4 reactions 0 assignees View on GitHub
wasmtime
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 19h
Merged PRs (30d)
121

Description

#### Feature

Over in #10620, @pchickey proposed stabilizing the format of `--invoke`. I think that makes sense, but it also caused me to revisit an idea I've had for a long time now: what if we taught `wasmtime` to generate nice, idiomatic CLIs from WIT exports?

To illustrate the idea, here's a simple example:

For this wit
```wit
/// A collection of tools that foo
export interface tools {
/// A foo function that foos as and bs into strings
foo: func(a: u32, b: string) -> string;
}
```

Wasmtime could generate this CLI interface:
```
$ wasmtime cli.wasm --help
A collection of tools that foo
Usage: cli.wasm

Commands:
foo A foo function that foos as and bs into strings

Options:
-h, --help Print help
-V, --version Print version

$ wasmtime cli.wasm foo --help
A foo function that foos as and bs into strings

Usage: cli.wasm foo [OPTIONS] [A] [B]

Arguments:
[A] A 32-bit integer
[B] A string

Options:
...

$ wasmtime cli.wasm foo 42 "or is it?"
The number 42 is very foo, or is it?
```

Lots of interesting questions around how to handle `arg-name: option` (turn into `--arg-name`?), more complex input types (e.g. accept file names, URLs, and pipes as inputs for streams?), satisfying imports, and others, but I think this would have a lot of potential.

#### Benefit

This would make it very easy to create simple CLI tools as components. What's more, nothing about these components would be specific to CLIs, necessarily. Instead, the same component could also be used as a building block for creating a web service, or as part of some data processing pipeline, etc.

#### Implementation

This being an idea more than a plan, I haven't dug into the implementation too much. The biggest issue I can foresee is defining good mappings from various input types (such as "just a string", filenames, URLs, pipes) to component types. Wasmtime would effectively have to act as a user agent, providing mappings from the shell domain into the component model domain.

#### Alternatives

Do nothing: this isn't some kind of urgent, mission-critical need.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.