Skip to content

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

Open
@tschneidereit

Description

@tschneidereit

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

/// 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 <COMMAND>

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<ty> (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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasmtimeIssues about wasmtime that don't fall into another label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions